By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,829 Members | 2,308 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,829 IT Pros & Developers. It's quick & easy.

<?= $some_var_or_other ?> ... <?php echo $some_var_or_other ?>

P: n/a
Hi...

I seem to remember reading somewhere about the proper way of doing this sort
of thing in the middle of some html, for example:

<a href="<?= $some_url_or_other ?>">Click this!</a>

What is the most proper way of doing such? Would it be to do the full
monty?:

<a href="<?php echo $some_url_or_other ?>">Click this!</a>

I am writing my output to be xhtml strict compliant, so I guess for
continuity alone it should be the latter, but are there any specific reasons
for using the long-winded way? I'd like to know people's thoughts...

HYCSSLOTS...
Plankmeister.
Jul 16 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
In article <3f***********************@dread16.news.tele.dk> , The
Plankmeister <plankmeister_NO_@_SPAM_hotmail.com> wrote:
<a href="<?php echo $some_url_or_other ?>">Click this!</a>


Use this one.
Jul 16 '05 #2

P: n/a
On Tue, 19 Aug 2003 02:16:13 -0600 in
<message-id:19**************************@linuxmail.org>
E-Star <un*******@linuxmail.org> wrote:
In article <3f***********************@dread16.news.tele.dk> , The
Plankmeister <plankmeister_NO_@_SPAM_hotmail.com> wrote:
<a href="<?php echo $some_url_or_other ?>">Click this!</a>


Use this one.

.... and to explain why to the OP...

<? ?> can be used if shorttags is enabled in php.ini but this isn't
always the case for every server and I suspect becoming less and less
the case as more and more people use XML for various tasks. XML uses
<?xml as it's tag, and causes confusion with PHP, so it's always
advisable (IMO at least) to use the <?php rather than <? (extending to
the echo <?php echo rather than <?= too).
HTH =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.
Jul 16 '05 #3

P: n/a
Ian.H [dS] wrote:
<? ?> can be used if shorttags is enabled in php.ini but this isn't
always the case for every server and I suspect becoming less and less
the case as more and more people use XML for various tasks. XML uses
<?xml as it's tag, and causes confusion with PHP, so it's always
advisable (IMO at least) to use the <?php rather than <? (extending to
the echo <?php echo rather than <?= too).


shorttags off has the advantage that you can use "<?xml" directly in
your files (i.e. without having to "print()" or "echo()" it), but if you
do that, you lose the ability to run your script on a server that has
shorttags on. If you're going to run only on servers who's php.ini you
control, that's no problem, but the default is still shorttags=on, so
that is what most hosters use.

So, if you're coding for the general public, shorttags=on is more
common, but you can't rely on it, so it is safer to use "<?php echo...".
But you can't rely on shorttags=off either, so for xhtml compliant files
you should use <?php echo "<?xml....";?>

Jochen

--
/**
* @author Jochen Buennagel <zang at buennagel dot com>
* @see http://www.sourceforge.net/projects/zang
*/

Jul 16 '05 #4

P: n/a
XHTML doesn't really care which version you use... The absolute best way
anyway seems to be <?PHP echo $url;?> Notice the ;... Doesn't matter though,
just that it seems better as chances are you might feel like extending that
piece of code and forget to att the ; at that point...

--
// DvDmanDT
MSN: dv******@hotmail.com
Mail: dv******@telia.com
"The Plankmeister" <plankmeister_NO_@_SPAM_hotmail.com> skrev i meddelandet
news:3f***********************@dread16.news.tele.d k...
Hi...

I seem to remember reading somewhere about the proper way of doing this sort of thing in the middle of some html, for example:

<a href="<?= $some_url_or_other ?>">Click this!</a>

What is the most proper way of doing such? Would it be to do the full
monty?:

<a href="<?php echo $some_url_or_other ?>">Click this!</a>

I am writing my output to be xhtml strict compliant, so I guess for
continuity alone it should be the latter, but are there any specific reasons for using the long-winded way? I'd like to know people's thoughts...

HYCSSLOTS...
Plankmeister.

Jul 16 '05 #5

P: n/a
"The Plankmeister" <plankmeister_NO_@_SPAM_hotmail.com> wrote in message news:<3f***********************@dread16.news.tele. dk>...
Hi...

I seem to remember reading somewhere about the proper way of doing this sort
of thing in the middle of some html, for example:

<a href="<?= $some_url_or_other ?>">Click this!</a>

What is the most proper way of doing such? Would it be to do the full
monty?:

<a href="<?php echo $some_url_or_other ?>">Click this!</a>


I prefer short tag <?=$foo?> 'cos it's IMO quite fast. Also, I
hate echo and would prefer to write PHP code without the use of echo.

(Many thanks to Rasmus for fighting on behalf of short tags:))
Jul 16 '05 #6

P: n/a
Jochen Buennagel wrote:
Ian.H [dS] wrote:
<? ?> can be used if shorttags is enabled in php.ini but this isn't
always the case for every server and I suspect becoming less and less
the case as more and more people use XML for various tasks. XML uses
<?xml as it's tag, and causes confusion with PHP, so it's always
advisable (IMO at least) to use the <?php rather than <? (extending to
the echo <?php echo rather than <?= too).

shorttags off has the advantage that you can use "<?xml" directly in
your files (i.e. without having to "print()" or "echo()" it), but if you
do that, you lose the ability to run your script on a server that has
shorttags on. If you're going to run only on servers who's php.ini you
control, that's no problem, but the default is still shorttags=on, so
that is what most hosters use.

So, if you're coding for the general public, shorttags=on is more
common, but you can't rely on it, so it is safer to use "<?php echo...".
But you can't rely on shorttags=off either, so for xhtml compliant files
you should use <?php echo "<?xml....";?>

Jochen

Or use:
if(ini_get('short_open_tag') == 'on') {
[code to be executed if shorttag is enabled]
}
else {
[code to be excecuted with shorttag disabled]
}

Robert

Jul 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.