PHP with HTML

+2 Robert Summers · October 27, 2014
Can someone help me embed this PHP in the HTML document and hide the php until needed or include two files, one PHP file and one HTML file. 


<?php

$string = 'This is an example string .';

//1 = show how many words in a array, 2 = how many letters via array
//add full stop / count as another array 
$string_word_count = str_word_count($string, 1, '.'); 

//Always use print_r to echo out arrays
print_r($string_word_count); 
echo '<br/>';

?>
<html lang="en">
<head>
<meta http-eqiv="Content-Type" type="text/html" charset="UTF-8"/>
<title>Robert's Website</title>
<link rel="stylesheet" href="main.css"/>
</head>
<body>
<p>This is a paragraph</p>
</body>
</html>

Many thanks for the help in return
Robert

Post a Reply

Replies

Oldest  Newest  Rating
+1 Ron Butcher · November 1, 2014
Just separate the code into two files.  The first one has the PHP, the second one has the HTML (both with the .php extension).  When you need to call the PHP code just use the include statement.


<?php include 'path_to_php_file.php'; ?>


That single line anywhere in your HTML code will open PHP and call your PHP code and print out what you need, then continue on with the rest of your HTML code.
  • 1

HTML / CSS / Web Design

107,158 followers
About

Discuss, share, ask, learn and teach HTML5 and CSS3.

Links
Moderators