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!
I have been PHP'ing for a while now but I have a very beginner question (or is it?)
Ever since I began to learn PHP I was told to use the long php tags like below, but once I have defined the php bit in the tag I dont do it again (am I making sense?)
Don't worry, n00b questions are what makes professionals out of newbies. =)
I always use <? and ?> because it's easier to type than <?php and ?>. Depending on wether or not your allow_short_tags is enabled in php.ini, you should be able to use them both in any script. I've done it before and it worked fine.
Ah, so you mean should you open it up with <?php, and if you ever open it again after closing it on the same document should you use <? or <?php ? I don't know that it will effect anything, but i always use <?php to start from anywhere in the document
Drachlen that is exactly what I mean, what you said.. this question is pretty pointless I guess and I don't think it really matters but it would be nice to know what the correct way of doing it is..
there's several styles. there's the <script language=php></script> style. this is a html style.
there's the the asp style. <% %>
then there's the SGML style that you're using IN the page: <? ?>
the difference between <? ?> and <?php ?> is that the first is for SGML, the second is for XML/XHTML
this means that since HTML is being phased out for XHTML you should get used to always using <?php ?> because unless your page is SGML then in the future, browsers may not recognise the <? ?> style.
right now the only reason to use <?php is that short tags are off. personally i prefer coding with portability.. expecting them to be off on the final server, so i've been using <?php ?>
btw: it's not a stupid question if you don't have the php book i have or a different one with the write up on the styles like i have. it makes sense to ask it....i mean, if you don't how can you know if you're picking up a bad habit?
actually there IS a difference between my post and drachlen's. he says he doesn't knwo what, if any affect it will have. i tell you the affect according to orielly.
the affect is whether the browser accepts SGML or not.
if you're coding xml you need the <?php instead of <?
html can use all the ones i mentioned, but not other forms. xhtml is NOT as forgiving as html, and since that is the future and it takes the <?php from xml instead of sgml's style, then in the future you will need <?php instead of <?
meaning as of now it depends on the php.ini script, but once browsers switch to xhtml and drop html, it WILL be the difference bwtween working and not working regaurdless
What they are telling you is that it doesn't make any difference.
Starting off with <?php will not cause a later <? to work if the <? wasn't going to work in the first place.
The initial use of the <? or <?php has no effect whatever on any subsequent uses of <? or <?php.
No disrespect to you guys but I did already know that it doesn't make any difference what you do but I just wanted to know if there was a official answer.