Page 1 of 1

PHP makes my brain hurt...

PostPosted: Mon Dec 26, 2005 7:59 pm
by Pepper Kittie
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*

PostPosted: Mon Dec 26, 2005 8:27 pm
by shooraijin
Whatever's outside of the PHP tags doesn't need it. Try it and see.

PostPosted: Tue Dec 27, 2005 3:24 pm
by Kaligraphic
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.)

PostPosted: Tue Dec 27, 2005 4:45 pm
by Pepper Kittie
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 ^^

PostPosted: Tue Dec 27, 2005 6:13 pm
by LorentzForce
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.