timlondon Posted February 7, 2007 Share Posted February 7, 2007 I've just had to reinstall php due to a system upgrade and my previous install worked using <? to open when code was being embedded within html. This worked fine on all of my pages. Subsequent to the re-install however, I now need to use <?php instead. This is very frustrating since I will need to amend the coding of about 50 pages. Is there a way I can alter the configuration of php so that it accepts <? ????? I'm using 5.2.0 Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/ Share on other sites More sharing options...
Balmung-San Posted February 7, 2007 Share Posted February 7, 2007 In the php.ini you need to set short_open_tag to 1. Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179126 Share on other sites More sharing options...
.josh Posted February 7, 2007 Share Posted February 7, 2007 ..and that's why you should use <?php instead of <? Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179127 Share on other sites More sharing options...
Balmung-San Posted February 7, 2007 Share Posted February 7, 2007 ..and that's why you should use <?php instead of <? Indeed. Especially since you never know when you'll move to a host which doesn't allows short tags, and won't let you change your php.ini Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179128 Share on other sites More sharing options...
.josh Posted February 7, 2007 Share Posted February 7, 2007 I suggest you just suck it up and change them. You can do a find and replace all, for each file. Or hell, write a script that will open each file and do it for you (I also suggest making backups first). Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179134 Share on other sites More sharing options...
Balmung-San Posted February 7, 2007 Share Posted February 7, 2007 preg_replace("<\?(?!php)","<?php",$line); Loop through each line in each file, and have that in the middle of the loop ($line being the line from the file you're currently on). That should work as a PHP script to do it for you. Interesting...using PHP to fix PHP... [EDIT]Added in negative lookahead to the regex, that way you don't replace <?php with <?phpphp. Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179135 Share on other sites More sharing options...
trq Posted February 7, 2007 Share Posted February 7, 2007 Hehe.. I wrote a solution to this yesturday using bash/sed. for file in $(ls -R projectdir/*.php) ; do sed -i -e 's/<?$/<?php/g' $file done Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179145 Share on other sites More sharing options...
timlondon Posted February 7, 2007 Author Share Posted February 7, 2007 Thanks guys. I'll take your advice and change them all. Quote Link to comment https://forums.phpfreaks.com/topic/37464-syntax-problem/#findComment-179162 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.