_
_ Handy PHP
_
_
Tutorials, Scripts, Information And Other Resources
Saturday, 06 September 2008
_

Refer A Friend using Revolution Money Exchange
Resource Menu
Handy PHP Store
Free Domain Name
PHP Functions
PHP Downloads
PHP Newsfeeds
PHP Tutorials
Webmaster Tools
User Login
TalkPHP
Get friendly help with your PHP problems for free.
www.talkphp.com
The PHP Resource Index
Handy PHP
Free PHP Help!

Newsflash

Here is a list of the top 5 resources here at Handy PHP currently:

JoomlaBoard SearchBot

Handy PHP Leading Zeros Function

Converting HTML to PHP Basic Tutorial

Handy PHP Build Input Field Function

Joomla/SMF SearchBot

 
Creating Your First Template Driven PHP Website Part 2 Print E-mail
Written by Handy PHP Administrator   
Wednesday, 25 April 2007

Until now, the PHP used has been pretty basic but the use of functions like file_get_contents, array, and preg_replace makes the code much more complicated and the use of these functions need to be discussed.

file_get_contents is used read the contnets of a file without the burden of using the file system and also allows for reading remote file contents. For example, using file_get_contents you can read any webpage on the Internet. Doing this, you will actually see the page the same way your web browser sees it, in raw HTML. So if you read a remote PHP file, you will only get it's output, not the actual source of the script. Here the function is used to assign the contents of the template.php file to the variable $template.

array is a commonly used function in PHP. You can think of an array like an multi-part variable. It will allow you to store many values in a single variable. Along with this function is several related functions which can help you sort the values in an array among other things. In this situation, we use 2 arrays for the search and replace system needed for the keywords. The 2 arrays are related to each other so the order of the first array must match the order of the second array. Some functions can cycle through the values in an array and apply it's command on each. Which brings us to the last function.

preg_replace is a replace function that uses regular expressions to identify a pattern in the string. A regular expressioncan be very simple or very complex depending on what you want to match. If you know exactly what you are looking for and that it will nevery vary in any way, the regular expression will be very simple but if you are looking for something that may vary greatly, the regulare expression will be very complex. A simple regular expression would be to find a specific word in a paragraph but a complex expression would be used to find every link on any website! Since the link will vary in position, title, url, extra parameters, and author style; you have to teach the script how to find a link. The preg_replace will look for the search term, replace it with the replace term, based on the string in the third argument. In our situation, the string is represented by the variable $template and the search and repace terms are represented by their repected arrays. This method can also be used to rewrite all of your links to something cleaner or filter out dirty words!

With a little planning and some hard work, you could convert your entire HTML website into a template driven PHP system.

In the next part, we'll look into data files and query string urls which will convert this static system into an generated on the fly dynamic system.

Enjoy your new template driven PHP site.

Discuss this article on the forums. (8 posts)



Last Updated ( Wednesday, 25 April 2007 )
 
< Prev   Next >

Who's Online
No Users Online
Polls
How long have you been using PHP?
 
What is your level of experience with PHP?
 
What is the most useful resource at Handy PHP.com
 
_
 
_
_
© 2008 Handy PHP