silly question?

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
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

silly question?

Post 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... :cry: :oops:
User avatar
m3mn0n
PHP Evangelist
Posts: 3548
Joined: Tue Aug 13, 2002 3:35 pm
Location: Calgary, Canada

Post 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.
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

that was not the question sami... read again..
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post 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
GK
Forum Commoner
Posts: 51
Joined: Sat Jun 07, 2003 2:58 pm
Contact:

Post 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 :)
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post 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.. :o
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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?
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post by m@ndio »

that wasn't the question but thankyou for the response, read drac's post.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post 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
User avatar
Bill H
DevNet Resident
Posts: 1136
Joined: Sat Jun 01, 2002 10:16 am
Location: San Diego CA
Contact:

Post 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.
User avatar
phice
Moderator
Posts: 1416
Joined: Sat Apr 20, 2002 3:14 pm
Location: Dallas, TX
Contact:

Post by phice »

It wouldn't hurt to do <?php every time. You're guarenteed for the script to work everywhere PHP is available.
Image Image
User avatar
m@ndio
Forum Regular
Posts: 163
Joined: Fri Jun 06, 2003 12:09 pm
Location: UK

Post 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. :?
Post Reply