> (greater than) recognized as end tag in php5 with apach

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
User avatar
martinco
Forum Newbie
Posts: 18
Joined: Mon Jun 25, 2007 10:06 pm
Location: Costa Rica

> (greater than) recognized as end tag in php5 with apach

Post by martinco »

hi!

i've recently installed apache2 and php5 locally on my computer, and installed a open source gallery.
in the source code there's a grater than comparisson between a variable and a number, but the > is recognized as an end tag :x (as if in the older version PHP/FI 2.0, see http://www2.stack.ru/~julia/PHP4/migration.php3.html).
the rest of the script after the grater than character if printed out in the document as html.
what can i do to prevent this from happening?
is there something to configure in the installation of apache or php?

thanks!
Last edited by martinco on Fri Jun 29, 2007 1:00 am, edited 1 time in total.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Is there a question mark attached to that greater than sign by any chance?

Otherwise, you sure your PHP 5 installation is configured correctly? Run phpinfo().
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

PHP 5 will not recognize a > as a closing tag.

Code: Select all

echo (10 > 20) ? 'test' : 'test';
Post the code & or exact error.
User avatar
martinco
Forum Newbie
Posts: 18
Joined: Mon Jun 25, 2007 10:06 pm
Location: Costa Rica

Post by martinco »

that simple test with echo perfectly works.

the gallery i installed is plogger (open source). i've installed it in a server via ftp before and worked perfectly. the think here has to do with my apache or php configuration, not with the script.

the script that causes the error is contained in the source file \lib\exifer1_4\exif.php of plogger. That file if called by the function require_one(...) in a file (admin\plog-admin-functions.php) that was called by include(...) in the file shown by the browser (admin\plog-upload.php and many others).

the 'grater than' character appears in the line 336 of exif.php :

Code: Select all

if($type=="SRATIONAL" && $top>2147483647) $top = $top - 4294967296;
all the script after that '>' is printed on the document "2147483647) $top = $top - 4294967296; //this makes the number signed instead of unsigned if($bottom!=0) $data=$top/$bottom; else if($top==0) $data = 0;" etc etc etc etc.... and after the end of the script comes the rest of the page.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

That makes no sense at all.

What happens if you change the line to...

Code: Select all

if ($type == "SRATIONAL" && ($top > 2147483647)) { $top = $top - 4294967296; }
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I guess the browser got the whole code and interpreted > as the end of one html tag.
Take a closer look at your opening tags. Do you use <? or <?php ?
Or is there by any chance a space between < and ? ?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

Argh, I've read about this issue before but can't remember where it was posted. I think it happens when your apache/php config has set it's start and end tags to <? and > but I'm not sure. I bet someone else here can shed a light onto this though.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if short_open_tags are disabled and the script uses them, e.g.

Code: Select all

<? if (3 > 4) { echo "..."; } ?>
then the whole script's code will be sent to the browser.
And the browser will interpret <? if (3 > as an broken tag/processing instruction and the rest is just text.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Run a regex enabled Find/Replace:

Code: Select all

Find: <\?(?!php|=)
Replace: <?php

Code: Select all

Find: <\?=
Replace: <?php echo
There an extra space at end of the second one, so be sure to add it.
User avatar
martinco
Forum Newbie
Posts: 18
Joined: Mon Jun 25, 2007 10:06 pm
Location: Costa Rica

Post by martinco »

now it works!! :D

in my php configuration the short_open_tag attribute was Off.
i'd read about it and decided to give it the default value (off). but now i see that the script that was bottering me uses short tags <? ... > :x

i decided to change my php configuration turning short_open_tag On instead of editing the original script.

"Pura vida!"
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

I'd highly suggest you don't. I believe short tags will be completely removed as of PHP6, so get used to not using them ASAP. I gave you the regex you need to remove them all. I had to do it once on someone else's files.
Post Reply