|
|
|
|
Like this code?
Show the author your appreciation.
|
|
| |
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);
}
?> | | |
| email validator check checker email e-mail email address Categories : PHP, Email, Regexps | | | Tag content retrieval from websites with preg_match Categories : PHP, Regexps, Arrays, HTML and PHP | | | PHP Script to find url links in a page Categories : PHP, URLs, Regexps, Arrays | |
| | FormChecker Package - validate any data via classes and patterns.
Categories : PHP, Form Processing, PHP Classes, Regexps | | | Form is a utility class for generating html forms. It provides form initialization and regex based data validation (both server and client side) with a convenient interface. This version obsoletes version 1.0a Categories : HTML, PHP, PHP Classes, Regexps | | | Gets the browser and OS from the $_SERVER['http_user_agent'] variable in PHP Categories : PHP, HTTP, Regexps | | | Avoiding or Detecting high bit characters in a string. Useful when you want to create a valid RSS feed Categories : PHP, Strings, Unicode, Regexps, Rich Site Summary (RSS) | | | Extract keywords from a string having words in " " count as one string. Categories : PHP, Strings, Regexps, Search | | | YellowPages Content Grabber (PHP5 +) Categories : PHP, PHP Classes, Regexps, Databases, MySQL | | | how to check if a string contains a letter from a different language? Categories : PHP, Regexps, Languages | | | Show Source with Line Numbers Categories : PHP, Regexps, Filesystem | | | PHP Domain Availability Checker Categories : PHP, Complete Programs, Regexps, HTTP, Sockets | | | A simple configuration file editor to ease you life in setting up php applications. Reads variables from a given file automatically and displays current value. New value will be written to file after submit. Categories : PHP, Filesystem, Regexps, Java Script | | | This script is a contact form between users of a
website (kinda like the PM function on the forums)
Categories : PHP, Databases, MySQL, Regexps | |
|
|