You accept to be included in our newsletter (We only send amazing freebies like this, no ads or crap, promise! )

Tweet about us and say thanks in comments ;)

Amazing freebies every week in your e-mail, don't miss the next ones with our newsletter, Sign up now.

Tweet about us and say thanks in comments ;)

Quick Tip: Echo() Function for PHP

Comments and suggestions in here
php00
Icon by Iconshock.
Today we like to recommend something nice for programmers, echo() is not function properly but a language construct, so you won’t need to use parentheses with it; echo() does not present a function behavior, which means that it cannot always be used in a function’s context. If you want to pass more than one parameter to echo(), the parameters must not be contained within parentheses. This short syntax only works with the short_open_tag configuration setting enabled.

Here’s an example of how echo() works:

<?php
echo "Hello World";

echo "This spans
multiple lines. The newlines will be
output as well";

echo "This spansnmultiple lines. The newlines will benoutput as well.";

echo "Escaping characters is done "Like this".";

// You can use variables inside of an echo statement
$foo = "foobar";
$bar = "barbaz";

echo "foo is $foo"; // foo is foobar

// You can also use arrays
$baz = array("value" => "foo");

echo "this is {$baz['value']} !"; // this is foo !

// Using single quotes will print the variable name, not the value
echo 'foo is $foo'; // foo is $foo

// If you are not using any other characters, you can just echo variables
echo $foo;          // foobar
echo $foo,$bar;     // foobarbarbaz

// Some people prefer passing multiple parameters to echo over concatenation.
echo 'This ', 'string ', 'was ', 'made ', 'with multiple parameters.', chr(10);
echo 'This ' . 'string ' . 'was ' . 'made ' . 'with concatenation.' . "n";

echo <<<END
This uses the "here document" syntax to output
multiple lines with $variable interpolation. Note
that the here document terminator must appear on a
line with just a semicolon. no extra whitespace!
END;

// Because echo does not behave like a function, the following code is invalid.
($some_var) ? echo 'true' : echo 'false';

// However, the following examples will work:
($some_var) ? print 'true' : print 'false'; // print is also a construct, but
// it behaves like a function, so
// it may be used in this context.
echo $some_var ? 'true': 'false'; // changing the statement around
?>


More freebies:

25 stickers for your iPad
Tron Legacy Icons
100 free @font-face fonts
Iconshock Social Icons, the most extensive and sexy set so far
Evolution vector set, awesome characters for free
Pure css3 buttons with hover effect

One Response to “Quick Tip: Echo() Function for PHP”

  1. Andrea ospin
    October 27th

    Thanks for the explanation…

Leave a Reply

*

Comments

CommentLuv badge

Featuring Recent Posts WordPress Widget development by YD