473,770 Members | 2,160 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

<?= $some_var_or_ot her ?> ... <?php echo $some_var_or_ot her ?>

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_ot her ?>">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_ot her ?>">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 2366
In article <3f************ ***********@dre ad16.news.tele. dk>, The
Plankmeister <plankmeister_N O_@_SPAM_hotmai l.com> wrote:
<a href="<?php echo $some_url_or_ot her ?>">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*******@linu xmail.org> wrote:
In article <3f************ ***********@dre ad16.news.tele. dk>, The
Plankmeister <plankmeister_N O_@_SPAM_hotmai l.com> wrote:
<a href="<?php echo $some_url_or_ot her ?>">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.ne t | 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******@hotmai l.com
Mail: dv******@telia. com
"The Plankmeister" <plankmeister_N O_@_SPAM_hotmai l.com> skrev i meddelandet
news:3f******** *************** @dread16.news.t ele.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_ot her ?>">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_ot her ?>">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_N O_@_SPAM_hotmai l.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_ot her ?>">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_ot her ?>">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('sho rt_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
6007
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 cdata sections will be echoed an not the element names as in the original example. In the cdata sections of my XML file I have terms like this:
7
5176
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
2577
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 class="none">over</span> the lazy dog should become The quick brown <span class="animal">fox</span> jumped over the lazy dog
1
6827
by: Christian Schmidbauer | last post by:
Hello! I prepare my XML document like this way: ------------------------------------------------------- PrintWriter writer; Document domDocument; Element domElement; // Root tag
2
10568
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 type="text/javascript"> <!]> </script> <script type="text/javascript"
11
13725
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, there's an "Edit" link. So the page itself looks something like this: <HTML><HEAD><TITLE>blah</TITLE></HEAD><BODY> <!-- TEXT STARTS HERE --> <H1>Hello World!</H1> <P>More stuff here...</P>
35
2035
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 display a database content, 25 rows at a time. The singleton keeps track of the current starting row and increases it or decreases it by 25 depending on the user action (pressing a Next or Prev button). Those buttons are submit buttons calling the...
4
1563
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 is in the same directory.
2
2206
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 = document.getElementById('1'); formdiv.innerHTML = formdiv.innerHTML +'<td align='center'><a href='#'><img border='0' src='../images/delete.gif'></td> '; } thats the Js function and thats the table which is generated through looping:
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10260
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8933
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4007
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.