WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Function for converting simple phpBB codes to html
Categories : PHP, Regexps Click here to Update Your Picture
Narcis Radu
Date : Dec 28th 2007
Grade : 5 of 5 (graded 1 times)
Viewed : 2091
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Narcis Radu
Action : Grade This Code Example
Tools : My Examples List

 
Like this code?
Show the author your appreciation.
Submit your own code examples 
 

While building small forums from scratch a php programmer should allow phpBB codes. The following function will help you parse and convert those codes in html.


<?php
function code_html($string) {

   
$string = str_replace(array('[BR]', '[br]'), array('<br />','<br />'),$string);
   
$string = preg_replace("/\[table=(.*?)\](.*?)\[\/table\]/ise","''.html_table('$1','$2').''",$string);
   
$string = preg_replace('/\[img\](.*?)\[\/img\]/is', '<img src="\1" \/>', $string);
   
$string = preg_replace('/\[center\](.*?)\[\/center\]/si','<div style="text-align:center;">\1</div>',$string);
   
$string = preg_replace('/\[i\](.*?)\[\/i\]/si','<i>\1</i>',$string);
   
$string = preg_replace("/\[b\](.*?)\[\/b\]/si",'<b>\1</b>',$string);
   
$string = preg_replace("/\[u\](.*?)\[\/u\]/si","<u>\\1</u>",$string);
   
$string = preg_replace("/\[hr\]/si","<hr />",$string);
   
$string = preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/ise","'[color='.stripslashes(str_replace('\"','','$1')).'] $2[/color]'", $string);
   
$string = preg_replace("/\[color=(.*?)\](.*?)\[\/color\]/ise","'<span style=\"color:'.stripslashes('$1').';\">$2</span>'",$string);
   
$string = preg_replace("/\[size=(.*?)\](.*?)\[\/size\]/ise","'[size='.stripslashes(str_replace('\"','','$1')).'] $2[/size]'", $string);
   
$string = preg_replace("/\[size=(.*?)\](.*?)\[\/size\]/ise","'<font size=\"'.stripslashes(str_replace('\"','','$1')).'\">$2</font>'", $string);
   
$string = preg_replace("/\[link=(.*?)\](.*?)\[\/link\]/si","<a href=$1 target=\"_blank\">\\2</a>", $string);
   
$string = preg_replace("/\[link=(.*?)\](.*?)\[\/link\]/si","<a href=\"$1\" target=\"_blank\">\\2</a>", $string);
   
$string = preg_replace("/\[a=(.*?)\](.*?)\[\/a\]/si",'<a href="$1">\2</a>', $string);
   
$string = preg_replace("/\[align=(.*?)\](.*?)\[\/align\]/ise","'[align='.stripslashes(str_replace('\"','','$1')).'] $2[/align]'", $string);
   
$string = preg_replace("/\[align=(.*?)\](.*?)\[\/align\]/ise","'<div align=\"'.stripslashes('$1').';\">$2</div>'", $string);
   
$string = preg_replace('/\[ul\](.*?)\[\/ul\]/si', '<ul>\1</ul>', $string);
   
$string = preg_replace('/\[ol\](.*?)\[\/ol\]/si', '<ol>\1</ol>', $string);
   
$string = preg_replace('/\[li\](.*?)\[\/li\]/si', '<li>\1</li>', $string);
   
$string = preg_replace('/\[em\](.*?)\[\/em\]/si', '<em>\1</em>', $string);
   
$string = preg_replace('/\[strong\](.*?)\[\/strong\]/si','<strong>\1</strong>', $string);
    return
nl2br($string);
}
?>



I need a trim function/regexp that will trim all " " from the ends of a string.
Categories : Regexps, PHP, Strings
Parse html (title :: meta)
Categories : PHP, HTML and PHP, Regexps
Parsing Simple Template Files and Data
Categories : PHP, PHP Classes, Templates, Regexps
How to check if a file is of type gif or jpg?
Categories : PHP, Regexps, Graphics
Query2Report : Generating Html, Pdf and Csv Reports from SQL Query
Categories : PHP, PHP, HTML, PDF, Excel
Check for functional file links (broken Files)
Categories : PHP, Data Validation, FTP, Regexps, Arrays
Banknote Validation - A PHP class that provides several methods to quickly validate banknote serial numbers of the following currencies: AUD, CAD, CHF, CNY, EUR, GBP, JPY, USD.
Categories : PHP, PHP Classes, Data Validation, Regexps
Grab links from a page
Categories : PHP, Regexps, HTTP
Match words that are entered into a <textarea> in any layout orientation (horizontal, vertical, diagonal).
Categories : PHP, Regexps
What is the best way to split a string that consists of two bits of data seperated by whitespace?
Categories : Regexps, Strings, PHP
Calculate Body Mass Index
Categories : PHP, Algorithms, Regexps
An array of functions to use in checking user input to HTML forms : text, firstName, middleNameOrInit, lastName, email, web, digits, decimal, hex, genNum, USD, BPS, Euro, USphone, USzip
Categories : PHP, Data Validation, Regexps
Ping a Server and run a command to fix it if it is down
Categories : PHP, Errors and Logging, Regexps
making links from text
Categories : PHP, Regexps, Email
php table decoder used to convert an html table to individual tokens through regular expressions
Categories : PHP, Regexps, HTML and PHP