Page 1 of 1
silly question?
Posted: Sun Jul 06, 2003 4:37 am
by m@ndio
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?)
Code: Select all
<?php //php long tag
//code here
?>
....Later on same script....
<? //no php bit
?>
If using the long tag style should you do the first example every time you break into some php?
what a n00b question...

Posted: Sun Jul 06, 2003 4:54 am
by m3mn0n
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.
Test it out and see what happens.
Posted: Sun Jul 06, 2003 7:04 am
by m@ndio
that was not the question sami... read again..
Posted: Sun Jul 06, 2003 8:30 am
by Drachlen
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
Posted: Sun Jul 06, 2003 11:35 am
by GK
i think drachelen is right
as far as i know u got to start <?php if you got external funtions in your script
But i'm not to sure about it LOL I'm a noob to LOL

Posted: Sun Jul 06, 2003 3:31 pm
by m@ndio
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..

Posted: Sun Jul 06, 2003 4:08 pm
by m3rajk
well it depends....
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?
Posted: Sun Jul 06, 2003 4:09 pm
by m@ndio
that wasn't the question but thankyou for the response, read drac's post.
Posted: Sun Jul 06, 2003 4:13 pm
by m3rajk
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
Posted: Sun Jul 06, 2003 11:12 pm
by Bill H
that wasn't the question
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.
Posted: Mon Jul 07, 2003 12:46 am
by phice
It wouldn't hurt to do <?php every time. You're guarenteed for the script to work everywhere PHP is available.
Posted: Mon Jul 07, 2003 3:36 pm
by m@ndio
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.
I appologise for my pointless post.
