Page 1 of 1
<?php ... ?> vs. <? ... ?> error
Posted: Mon May 08, 2006 5:24 pm
by empiresolutions
I have just upgraded my LAMP server to PHP 5.1.1. Now my all my pages on all my sites are messed up. I have figured out that it is because I donot use <?php ... ?> to write php in. i just use <? ... ?>. Seems without the "php" in the tag it will not display properly.
Is there a switch in the php.ini file or in apache that needs to be tripped so that it accepts all my thousands of legacy php tags?
Thank you, Cesar
Posted: Mon May 08, 2006 5:37 pm
by empiresolutions
ok got it, update php.ini as follows.
*php.ini becomes php.ini.rpmsave in PHP 5*
; Allow the <? tag. Otherwise, only <?php and <script> tags are recognized.
; NOTE: Using short tags should be avoided when developing applications or
; libraries that are meant for redistribution, or deployment on PHP
; servers which are not under your control, because short tags may not
; be supported on the target server. For portable, redistributable code,
; be sure not to use short tags.
short_open_tag = On
Now it works!! Woohoo.
Posted: Mon May 08, 2006 5:42 pm
by feyd
short_tags which is a php.ini directive.
It is best to alter all of your files to add the correct tags however. This can be done via a script or command-line fairly easily, although it does rely a bit on how you vary in the usage:
Code: Select all
[feyd@home]> php -r "foreach(glob('*.php') as $file) { file_put_contents($file, preg_replace(array('#<\?\s*=#s', '#<\?(\s*)#s'), array('<?php echo ', '<?php$1'), file_get_contents($file))); }"
It may need a little tweaking depending on if I wrote it right (did it from memory) and based on how your write your code most often, but should work for most instances. Run that in each directory you have scripts in that use short tags.
Posted: Mon May 08, 2006 5:49 pm
by empiresolutions
i understand that short tags is not the best way to write and i will change from here on out. i really am interested in the script you have created. Can you bust out a version that will work locally?
And what do you mean by
although it does rely a bit on how you vary in the usage:
thank you.
Posted: Mon May 08, 2006 5:53 pm
by feyd
The version I posted is intended for the command line.
As for "how you vary in the usage," what I mean is how you write the short tags. There are multiple ways to write the short tags, some are far more common than others. Examples of the common ways:
The code I posted is intended for the common ways.
Posted: Tue May 09, 2006 5:48 am
by dibyendrah
feyd wrote:short_tags which is a php.ini directive.
It is best to alter all of your files to add the correct tags however. This can be done via a script or command-line fairly easily, although it does rely a bit on how you vary in the usage:
Code: Select all
[feyd@home]> php -r "foreach(glob('*.php') as $file) { file_put_contents($file, preg_replace(array('#<\?\s*=#s', '#<\?(\s*)#s'), array('<?php echo ', '<?php$1'), file_get_contents($file))); }"
It may need a little tweaking depending on if I wrote it right (did it from memory) and based on how your write your code most often, but should work for most instances. Run that in each directory you have scripts in that use short tags.
interesting script ! I have been using search and replace tool to do that till now like regexxer in linux.
Thank you for the simple mechanism feyd !
Cheers,
Dibyendra