473,327 Members | 2,118 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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

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
6 2345
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
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
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
7
by: haoren | last post by:
Can anybody help me with this problem: How can I echo a string that contain <? and <?php? For example, $str="test <? and <?php echo"; echo $str;
3
by: Alexander Ross | last post by:
I have an html snippet, and I want to remove any <span> tags that have a specific attribute (class=none) ex. The quick brown <span class="animal">fox</span> jumped <span...
1
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
2
by: Donald Firesmith | last post by:
I am having trouble having Google Adsense code stored in XSL converted properly into HTML. The <> unfortunately become &lt; and &gt; and then no longer work. XSL code is: <script...
11
by: Les Paul | last post by:
I'm trying to design an HTML page that can edit itself. In essence, it's just like a Wiki page, but my own very simple version. It's a page full of plain old HTML content, and then at the bottom,...
35
by: Steve JORDI | last post by:
Hi, I'm trying to implement a singleton in PHP4 but it doesn't seem to work. The object is recreated each time I call it. The goal of the class is to keep a variable up to date. It's used to...
4
by: pplers | last post by:
Here is config.php: <?php //The vars are all ok. $dbhost = 'localhost'; $dbname = 'forum'; $dbuser = 'toor'; $dbpass = ''; ?> Here is a part of functions.php: <? require "config.php"; //It...
2
by: jessy | last post by:
I have a table at which i need to add fields in it whenever the user clicks on the Add button , here's my trial but seems sth is wrong : function AddTool() { formdiv =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.