Quoted string with angle bracket won't print without space

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
joeshmoe666
Forum Newbie
Posts: 7
Joined: Sat Sep 12, 2009 2:02 pm

Quoted string with angle bracket won't print without space

Post by joeshmoe666 »

This is driving me nuts.. I know it's something really obvious but when I run this code it prints nothing :

<?php
$Test="hello";
$request="<a";
print_r($request);
exit;
?>

The only way it prints is if I put a space after the angle bracket like this:

<?php
$Test="hello";
$request="< a";
print_r($request);
exit;
?>

Anyone know what the problem is ??

Thanks in advance
Joe
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Quoted string with angle bracket won't print without space

Post by requinix »

The <a is there - you're just not seeing it. It's being interpreted as HTML markup. Check the HTML source of the page.

Code: Select all

$request=htmlentities("<a"); // <a
joeshmoe666
Forum Newbie
Posts: 7
Joined: Sat Sep 12, 2009 2:02 pm

Re: Quoted string with angle bracket won't print without space

Post by joeshmoe666 »

Afraid that's not it .. put any character instead of the a and it still does the same thing .. and even if it were reading it as html it should still output it since it's a quoted string..
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

Re: Quoted string with angle bracket won't print without space

Post by Eran »

did you try it?
joeshmoe666
Forum Newbie
Posts: 7
Joined: Sat Sep 12, 2009 2:02 pm

Re: Quoted string with angle bracket won't print without space

Post by joeshmoe666 »

Sorry .. you're right .. the original problem was I was sending XML to a server and getting an error so I was trying to print out the xml to my screen so I could see if it was formed correctly .. and of course you're right that you can't view the xml that way since it has the < in it .. I can print it to the screen and view it with page source though .. so now I can get back to the original problem .. interesting side track though .. arghh!!

Thanks
Post Reply