php doing things recursively

hero080

New Member
Messages
16
Reaction score
0
Points
0
Code:
<?php
$str = "<?php";
echo $str;
?>
I expected to see "<?php" as the output. However, the output seems to be interpreted as php code and executed again by the server and at the end I get nothing for output.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
When you run the page, look at the source (ie 'View Source" )

The output is there. Just not visible due to the fact the browser thinks < is starting an html tag and does not display it.
 

hero080

New Member
Messages
16
Reaction score
0
Points
0
You should be correct, and what you said is exactly what I thought.
However, by viewing the source of the page, I found nothing there.

Nonetheless, your way did work. Use &lt; to replace the < did solve this problem.
 

descalzo

Grim Squeaker
Community Support
Messages
9,373
Reaction score
326
Points
83
Interesting, which browser do you use?
FireFox shows a blank page, but the source reveals the output.
IE8 shows the output as text
Chrome seems to show nothing in display or source.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Chrome appears to strip XML processing instructions, even when displaying an unrendered view of the response body.

Code:
<?foo ?>bar<?qux quux?>

If you set the content type to "text/plain", you'll see everything.

PHP:
<?php header('Content-type: text/plain'); $fmt='<?php header(\'Content-type: text/plain\'); $fmt=\'%s\'; printf($fmt, addcslashes($fmt, \'\\\'\\\\\')); ?>'; printf($fmt, addcslashes($fmt, '\'\\')); ?>

Also, Chrome will display output in the source view after a "?>".
PHP:
<?php $fmt='<?php $fmt=\'%s\'; printf($fmt, addcslashes($fmt, \'\\\'\\\\\')); ?>'; printf($fmt, addcslashes($fmt, '\'\\')); ?>
 
Last edited:

hero080

New Member
Messages
16
Reaction score
0
Points
0
That's it. I was using chrome.
Now I know that "viewing source" won't necessarily give me the real source. Chrome the cheater!
 
Top