Solved

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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 …

760 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

18 Experts available now in Live!

Get 1:1 Help Now