Solved

PHP String output shortcut, like ASP <%=aspVar%>

Posted on 2004-09-11
4
382 Views
Last Modified: 2006-11-17
Does a shortcut exist in PHP 4.3.x + that is analogous to the ASP shortcut for Response.Write, <%= %>?

At present I am using inline with HTML.

<?php print("{$myVar}"); ?>

 This is sufficiently short, but I'm simply curious if an even shorter form exist.

Thanks
0
Comment
Question by:lgawlik
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Diablo84 earned 50 total points
ID: 12035518
<?= $myVar ?>

can be used if short tags are enabled in the php.ini file
0
 
LVL 2

Author Comment

by:lgawlik
ID: 12035603
Thanks Diablo,

I'm adding PHP to my set of skills, it's always handy to know the shortcuts.
0
 
LVL 27

Expert Comment

by:Diablo84
ID: 12035627
no problem

And good luck learning PHP. I considered learning ASP awhile back to broaden my knowledge but the syntax seems very over complicated comparred to PHP so I think il stay put.


Incidently, for your information, the original example you gave:

<?php print("{$myVar}"); ?>

can be greatly simplified as:

<?php print $myVar; ?>

With both echo and print the round brackets are optional, quotes are only needed when outputting a string or a string and a variable, variables alone don't need them. Also the curly brackets only need to be used in certain situations such as when outputting an array item, super global etc, eg:

<?php echo "a string containing post data: {$_POST['var']} and other items"; ?> *

Standard variables can be outputted in this fashion like so:

<?php echo "a string containing a local variable $var and other items"; ?>


* This is the equivalent of concatenating the string, eg:

<?php echo "a string containing post data: ".$_POST['var']." and other items"; ?>


Hope that helps :)
0
 
LVL 2

Author Comment

by:lgawlik
ID: 12035661
Perfect answer and thanks for the tips.  

I typically code using ASP or ASP.NET for web apps.  I worked lightly with PHP 3.x but never really learned to like it much.  What a difference the 4.3.x and 5 versions are.  I would be developing for the 5 platform using quite a bit more OO, but my client is only running 4.3.8; oh well.

Thanks again for the help and tips.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
PHP query / monitor data from Telnet to MySQL 7 48
Email called spam 5 36
Wordpress Cron - Send XML Data to external server FTP 3 22
Help with PHP 13 27
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question