Interesting thing I just learned about outputting text
Most PHP books begin by telling you how you can output text using echo or print. I find it interesting how the langauge can display text without even any explicit function calls:
PHP Code:
<?
$test=1;
if ($test==1){
?>
<b>This text is displayed if $test equals 1</b>
<?
}
?>
Coming from JavaScript, this really illustrates how PHP is a server side language, and JavaScript is not
__________________
- George
- JavaScript Kit- JavaScript tutorials and 400+ scripts!
- JavaScript Reference- JavaScript reference you can relate to.
<html>
<body>
<?echo $php_var;?>
..some html
<?echo $another_var;?>
</body>
</html>
as PHP ignores anything that is not enclosed in PHP tags and parses the bits it finds.
another excellent saver is
<?readfile('some_file.txt);?>
which passes the contents of some_file.txt directly to the browser so its a bit like using include() only a little faster (good for big blocks of text/html)
other lifesaver that most PHPers find out after hours of string_replace()ing etc , is
echo nl2br($string);
which takes text from input with newlines (say a textarea) and tags a <br /> onto the end for you (XHTML compliant as well!) - the newline is not replaced so your code still looks neat when you view source etc , &
trim($string)
which cleans up whitespace and newlines especially good for password input etc
just thought I would pop those out now as they are perhaps where I wasted the most time when I started with PHP ... anyone else with any lifesavers ??
MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)
Yes that is heredoc syntax. Available since php4. You can also store it in a variable for echoing at a later time as well. I used it in a reply for someone else here