could u explain why for these fun lines?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

could u explain why for these fun lines?

Post by php12342005 »

first all, do not simply give me a link, i did read many docs from google but i can not find answer.
explain first, then links - thanks.

followings are code in a php file but out of <?php?> tag.

===============================================
<?php $var0="hello, boys"; ?>

<form>
<input type="text" value=<?php print("'$var0'"); ?> style="width:200;">
<br>
<input type="text" value=<?php print("$var0"); ?> style="width:200;">
<br>
<input type="text" value=<?php print($var0); ?> style="width:200;">
</form>

<?php print("'$var0'"); ?>
<br>
<?php print("$var0"); ?>
<br>
<?php print($var0); ?>
<br>
===============================================
output:
-------------- first 3 lines (in inputs) are:
hello, boys
hello,
hello,
-------------- last 3 lines (not in inputs) are:
'hello, boys'
hello, boys
hello, boys

if you compare a line (in input) with respective line (not in input), you see they are different.

what does first 3 lines mean?
(last 3 lines are easy to be understood)

why?

by the way: is print() the same as echo()?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

It means that you are generating invalid (X)HTML.
by the way: is print() the same as echo()?
If you read the manual carefully, not the way you did now, you should know the answer.
Ree
Forum Regular
Posts: 592
Joined: Fri Jun 10, 2005 1:43 am
Location: LT

Post by Ree »

you have invalid input's.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

php12342005 are you doing it on purpose??? Use

Code: Select all

tags please... I'm not doing it for you this time.. every time we ask you you do not seem to be taking it on board - in fact, you argued against it the last time   

68 posts - still not listening.
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post by harrisonad »

The HTML you generated is

Code: Select all

&amp;lt;form&amp;gt; 
&amp;lt;input type=&quote;text&quote; value='hello, boys' style=&quote;width:200;&quote;&amp;gt;&amp;lt;br&amp;gt; 
&amp;lt;input type=&quote;text&quote; value=hello, boys style=&quote;width:200;&quote;&amp;gt;&amp;lt;br&amp;gt; 
&amp;lt;input type=&quote;text&quote; value=hello, boys style=&quote;width:200;&quote;&amp;gt; 
&amp;lt;/form&amp;gt;
The first line is the standard way to write tag attribute values using either " or '. The last two are not. Whenever you deprive the value from quotes, HTML will take the first word, in your case, 'hello,' as its valid value. And the rest of the sentence will be ignored.
Now if you are complaining about the quotes not showing up in the textbox, its normal. But if you want so, it must be generated as this...

Code: Select all

value=&quote;'hello, boys'&quote;
in php ...

Code: Select all

value=<?php print("\"'hello, boys'\""); ?>
Post Reply