Home
   <<
Concatenating PHP and HTML
Post / Update: 05/05/10
Views: 2260

PHP as every internet language, is compatible with HTML. But how to combine the two? Simple: either we write HTML separated from PHP or simply send PHP to write the HTML while processing. But always within a PHP file. Create a file called 'testehtml.php', save it in the folder 'www' in EasyPHP folder and then call it in the browser address http://127.0.0.1/testehtml.php, but rather, write the instructions below in File:

Ex. 1:
<html>
<head><title>My page</title></head>
<body>
<?php

$i = 0;
$myVar = 'Test with loop<br />';
echo $myVar;
While($i < 10){
echo $i.'<br />'; // apostrophe concatenates with a point (.)
$i++;
}

?>
</body>
</html>



Or,
Ex. 2:
<?php

echo '<html>';
echo '<head><title>My page</title></head>';
echo '<body>';
$myVar = 'Test with loop<br />';
echo $myVar;
While($i < 10){
echo "$i<br />"; // quotes do not need to concatenate
$i++;
}
echo '</body>';
echo '</html>';

?>
It's possible too stop the PHP blocks, write HTML and then insert new blocks PHP on the same page. But whenever writing the blocks PHP, it is necessary that your code is between the tags<?php ...; ?> even at a page with PHP extension, if not, it will be viewed as plain text by the interpreter.

For any doubts, you can access blogs, forums and the PHP page: http://www.php.net.
 PHP Course

Last post

Post/Update: 14/09/10

Structure, as its name implies, determines how a document or a particular composition are organized. In the case of control structures, it determines how flow the reading and processing in programming languages.

In the case of PHP, there are three...
 << See more



 Estou Hospedado na EazzyHost Design | Illustration | Programming