PHP makes my brain hurt...

Homework giving you a headache? Math gives you a migraine? Can't quite figure out how to do something in photoshop? Never fear, the other members of CAA share their expertise in this forum.

PHP makes my brain hurt...

Postby Pepper Kittie » Mon Dec 26, 2005 7:59 pm

I need some help with PHP, if anyone can help me ^^ I don't know much about it... Inkhana's been teaching me a lot of things, and I've gotten to where I can make a decent layout with it. (though it took a million tries!) But there's still a lot about PHP that I don't quite understand. I know that you can't have quotation marks " unless you have a \ before them, but that also affects html tags inside of the PHP page, doesn't it? My question is how do you have an image tag on your page (<img src=" ) if PHP doesn't like the quotation marks, or can you put backslashes into HTML tags too?

... I hope that made sense. I'm confusing myself just by asking XD I just want to know how I can have images on my PHP pages. Any ideas, wonderful CAA PHP gurus out there? Pweeeeze? *big adorable kitty eyes*
"The thief comes only to steal and kill and destroy; I have come that they may have life, and have it to the full."
~John 10:10

~* Advocate Voice *~
User avatar
Pepper Kittie
 
Posts: 143
Joined: Fri Feb 06, 2004 5:28 pm
Location: I live in the US. I'm studying in South America.

Postby shooraijin » Mon Dec 26, 2005 8:27 pm

Whatever's outside of the PHP tags doesn't need it. Try it and see.
"you're a doctor.... and 27 years.... so...doctor + 27 years = HATORI SOHMA" - RoyalWing, when I was 27
"Al hail the forum editting Shooby! His vibes are law!" - Osaka-chan

I could still be champ, but I'd feel bad taking it away from one of the younger guys. - George Foreman
User avatar
shooraijin
 
Posts: 9927
Joined: Thu Jun 26, 2003 12:00 pm
Location: Southern California

Postby Kaligraphic » Tue Dec 27, 2005 3:24 pm

There are a couple of ways of dealing with the issue - what Shooraijin is talking about is just having the PHP code in <?php ?> tags, with most of the html outside of them - and thus unaltered.

For example...
Code: Select all
...html stuff...
<?php
PHP stuff
?>
...more html stuff...


Where you output html code from PHP you'll need the backslashes, but not outside of your PHP start and end tags.

You can even open a PHP block mid-tag - for example, this would work:
Code: Select all
<img src="<?php echo($imgurl); ?>" alt="<?php echo($imgalttext); ?>">


(note that with echo you can only pass one thing in parentheses, otherwise you have to put the stuff you want to output out in the open. I just like parentheses for concision and clarity.)
The cake used to be a lie like you, but then it took a portal to the deception core.
User avatar
Kaligraphic
 
Posts: 2002
Joined: Wed Jul 21, 2004 12:00 pm
Location: The catbox of DOOM!

Postby Pepper Kittie » Tue Dec 27, 2005 4:45 pm

Oh! I get it ^__^ Thank you two. I didn't think HTML would work if I put backslashes into it, but it does. I should've just tried that in the first place but I wasn't sure if it would mess something up. Thanks for the advice and help, I'll remember those things. It's fixed now ^^
"The thief comes only to steal and kill and destroy; I have come that they may have life, and have it to the full."
~John 10:10

~* Advocate Voice *~
User avatar
Pepper Kittie
 
Posts: 143
Joined: Fri Feb 06, 2004 5:28 pm
Location: I live in the US. I'm studying in South America.

Postby LorentzForce » Tue Dec 27, 2005 6:13 pm

To be specific;

" s are "magical", and means before it is went through it is checked of any variables starting with $. Yes, this means PHP will do whatever it takes to figure out if there really is a variable if it sees a $ between your ""s.

This is where ' comes in. This is just straight off deal, and also, no need to \ the "s when they are found. However, you have to \ the 's that are between ''s.

So, in the end;

Code: Select all
// When you use ""

$base = "Pies";

echo "All your $base are belong to us."
// All your Pies are belong to us.

echo 'All your $base are belong to us.'
// All your $base are belong to us.

echo "All your ' are belong to us."
// All your ' are belong to us

echo 'All your " are belong to us.'
// All your " are belong to us.

echo '<img src="foo.png" alt="bar">';
// ...will print out just that. No need to \ those "s.

Image
User avatar
LorentzForce
 
Posts: 1263
Joined: Sun Jun 01, 2003 3:18 am
Location: Between B and E


Return to Tutorials

Who is online

Users browsing this forum: No registered users and 22 guests