Solved

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

Posted on 2004-09-11
4
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

735 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