<?php versus <?

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
ptityop
Forum Newbie
Posts: 13
Joined: Thu May 07, 2009 1:48 pm

<?php versus <?

Post by ptityop »

Hi all!
I have a client website I am working on, I am not a php guru, I need to work on the design, so I installed the site on my machine but I am encountering a pb with the code ... with my little knowledge I found out that the issue lies in the <? tags that seem to need to be converted into <?php, well some of them anyway.... so I started to dig in the code but was wondering if there is another way to sort this problem without having to get in the code , because I also realize that not all <? need to be changed and I am doing it on a trial & error basis which is a pain in the ***** especially for someone like me...
Any help would really be appreciated before I do something wrong.
Many thanks in advance.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: <?php versus <?

Post by requinix »

You should try to use <?php. It will always work, unlike <?.
ptityop
Forum Newbie
Posts: 13
Joined: Thu May 07, 2009 1:48 pm

Re: <?php versus <?

Post by ptityop »

Yes the thing is I did not write the script... but basically I just enabled the Short Tag option in php.ini and it's all working fine now...just hope the tags I changed will not have any consequences ..but everything sems to be fine on my local machine..
Thanks !
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: <?php versus <?

Post by califdon »

As Hamlet said, "Aye, there's the rub!" -- "everything sems to be fine on my local machine" -- not a good basis for programming, in general. As tasairis said, the proper solution is to use a simple text editor and do a 10-second find-and-replace on each script. Can't get any easier than that.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Re: <?php versus <?

Post by CoderGoblin »

The reason you generally use the full tag is to ensure compatibility no matter what the server settings are. Yes it's a quick fix to put short tags on but what ever happens if these tags are not allowed and you need to reuse the code. It's always better to use the lowest common settings.

As mentioned changing all the tags shouldn't take long and personally I find it more readable.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Re: <?php versus <?

Post by Ollie Saunders »

because I also realize that not all <? need to be changed
That would be pretty unusual. The short_open_tag setting, in PHP, applies to everything that runs with it. The only way an exception could be made to that would, possibly be, turning it back on at runtime (with ini_set() perhaps) or a manually coding a way of using <? despite short_opens_tags = false; I did that once. Even if that's the case, it's extremely doubtful any harm could be done by changing <? to <?php; so, as others have suggested, just do a find-replace.
User avatar
Sindarin
Forum Regular
Posts: 521
Joined: Tue Sep 25, 2007 8:36 am
Location: Greece

Re: <?php versus <?

Post by Sindarin »

I had this problem before. My suggestion is to use <?php where possible and avoid <? and <?=, this will make your code more portable.

Quick fix for this would be to find and replace as suggested. If you have Dreamweaver, it can search and replace the tags in all your site documents/folders.

replace <? with <? and
replace <?= with <?php echo
Post Reply