Good day.
Is there a simplified method of outputting information from a PHP variable, without resorting to <?php echo ?> or <?php print() ?>? I am basically looking for something akin to <%= %> from ASP.
I recently decided to learn PHP and MySQL. I am familiar with most of ASP's conventions (at least on a simplistic level), but although ASP and PHP have general similarities, some of the logic and format is quite different. I know of the obvious resources for finding functions and whathaveyou (php.net's reference manual), but I wasn't sure how to search for the question above.
My apologies if this is rather more basic than what you normally on the forum. Additionally, if you know of a good guide to outline basic differences between ASP and PHP I would be most gracious. My thanks for your time.
- Niveras
Newbie question: output shorthand
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Short-tags (<?) are considered bad by practice by some because of the possible confusion with XML:
Code: Select all
<?xml version="1.0"?>If php accepts <?, <?= or even <% is controlled by the config parameters short_open_tag and asp_tags
Re: Newbie question: output shorthand
Years ago I switched from ASP to PHP, and my advice would be that you shouldn't try to write ASP code in PHP's syntax. Try to forget as much of your ASP knowledge as possible while you're writing PHP. While PHP lets you hack in shorthand outputs like <?=$var?> doing so is a really bad idea. It's a bad idea in ASP too. It's a clear indicator that you're mixing code and HTML more than you really should be.Niveras wrote:Is there a simplified method of outputting information from a PHP variable, without resorting to <?php echo ?> or <?php print() ?>? I am basically looking for something akin to <%= %> from ASP.
I recently decided to learn PHP and MySQL. I am familiar with most of ASP's conventions (at least on a simplistic level), but although ASP and PHP have general similarities, some of the logic and format is quite different. I know of the obvious resources for finding functions and whathaveyou (php.net's reference manual), but I wasn't sure how to search for the question above.
My thanks for all the replies. I think in the interest of conventions I'll just rely on using printf() or echo as the situation demands; might even force me to use a more efficient means since it won't permit me to be so lazy.
Apparently, on a more embarrasing note, my question was actually answered under the 'Basic Syntax' of PHP's manual. Perhaps I should take Vodka's signature to heart in the future~
- Niveras
Apparently, on a more embarrasing note, my question was actually answered under the 'Basic Syntax' of PHP's manual. Perhaps I should take Vodka's signature to heart in the future~
- Niveras