Link to home
Start Free TrialLog in
Avatar of lgawlik
lgawlik

asked on

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

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
ASKER CERTIFIED SOLUTION
Avatar of Diablo84
Diablo84

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lgawlik
lgawlik

ASKER

Thanks Diablo,

I'm adding PHP to my set of skills, it's always handy to know the shortcuts.
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 :)
Avatar of lgawlik

ASKER

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.