Output Shortcut

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
r_barlow
Forum Newbie
Posts: 17
Joined: Mon May 29, 2006 3:13 pm

Output Shortcut

Post by r_barlow »

Hey,

I'm new to PHP but have developed pages in other languages such as JSP.

I was wondering if PHP has a shortcut to insert output so you don't have to write <? echo (stuff); ?> all the time.

For example, in JSP you could either do:

<% out.println(x); %>

or

<%= x%>

Thanks
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

<?= $var ?>

But don't rely on it.... it requires servers to have short tags enabled in php.ini (which I believe is due to be removed in PHP6).
r_barlow
Forum Newbie
Posts: 17
Joined: Mon May 29, 2006 3:13 pm

Post by r_barlow »

Ahh ok thanks.. another question that is kind of related is I'm looping through database records and outputting for each record. When I look at the generated html, all the outputs from the echos are grouped together in one big paragraph. Is there a way to make the echo space down? (print vs. println in JSP)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

r_barlow wrote:Ahh ok thanks.. another question that is kind of related is I'm looping through database records and outputting for each record. When I look at the generated html, all the outputs from the echos are grouped together in one big paragraph. Is there a way to make the echo space down? (print vs. println in JSP)

Code: Select all

echo "\n";
It's \r\n in windows (and just \r on a mac i think).

Quick function for it:

Code: Select all

function println($str)
{
    echo $str."\n";
}
r_barlow
Forum Newbie
Posts: 17
Joined: Mon May 29, 2006 3:13 pm

Post by r_barlow »

Awesome.. thanks a lot!!
Post Reply