Something Useful
Example 2-5. Mixing both HTML
and PHP modes
<?php
if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false)
{
?>
<h3>strpos must have returned non-false</h3>
<center><b>You are using Internet Explorer</b></center>
<?php
} else {
?>
<h3>strpos must have returned false</h3>
<center><b>You are not using Internet Explorer</b></center>
<?php
}
?>
A sample output of this script may be:
<h3>strpos must have returned non-false</h3>
<center><b>You are using Internet Explorer</b></center>
Instead of using a PHP echo statement to output something,
we jumped out of PHP mode and just sent straight HTML. The
important and powerful point to note here is that the logical
flow of the script remains intact. Only one of the HTML
blocks will end up getting sent to the viewer depending
on the result of strpos(). In other words, it depends on
whether the string MSIE was found or not.
|