Solved

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

Posted on 2004-09-11
4
367 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

914 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now