Zangeel
11-16-2008, 06:04 PM
This can help jumpstart you creating text validations.. parses urls, and has some bbcode.. work off it.
<?php
class TextClass
{
public function Parse($sText)
{
if (!function_exists(stripos)) {
function stripos($string, $word)
{
$retval = false;
for ($i = 0; $i <= strlen($string); $i++) {
if (strtolower(substr($string, $i, strlen($word))) == strtolower($word)) {
$retval = true;
}
}
return $retval;
}
}
if (stripos($sText, "a href") === false) {
if (stripos($sText, "img") === false) {
if (stripos($sText, "[/link]") === false) {
if (stripos($sText, "src=") === false) {
if (stripos($sText, "[/url]") === false) {
$sText = " " . $sText;
$sText = eregi_replace('(((f|ht){1}tps?://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=\"_blank\">\\1</a>', $sText);
$sText = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target=_blank>\\2</a>',
$sText);
$sText = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $sText);
}
}
}
}
}
$Arr = array(
"/\(.+?)\[\/b\]/si",
"/\[i\](.+?)\[\/i\]/si",
"/\[quote=(.+?)\](.+?)\[\/quote\]/si",
"/\[quote\](.+?)\[\/quote\]/si",
"/\[url=(.+?)\](.+?)\[\/url\]/si"
);
$Rep = array(
"<b>$1</b>",
"<i>$1></i>",
"<blockquote>$1 <b>Said</b> <br /> $2</blockquote>",
"<blockquote>$1</blockquote>",
"<a href=\"$1\" target=\"_blank\">$2</a>"
);
$sText = preg_replace ($Arr, $Rep, $sText);
return $sText;
}
}
example usage
require ('Text.class.php');
$oTxt = New TextClass;
$Str = "This is a test [b]string to test the text class out. <br><br> hello there how are you test test test test test test test test test test test test test test test <br><br><br> www.google.com ... http://www.google.com ...emai@eamil.com<BR><BR><BR>";
echo $oTxt->Parse($Str);
<?php
class TextClass
{
public function Parse($sText)
{
if (!function_exists(stripos)) {
function stripos($string, $word)
{
$retval = false;
for ($i = 0; $i <= strlen($string); $i++) {
if (strtolower(substr($string, $i, strlen($word))) == strtolower($word)) {
$retval = true;
}
}
return $retval;
}
}
if (stripos($sText, "a href") === false) {
if (stripos($sText, "img") === false) {
if (stripos($sText, "[/link]") === false) {
if (stripos($sText, "src=") === false) {
if (stripos($sText, "[/url]") === false) {
$sText = " " . $sText;
$sText = eregi_replace('(((f|ht){1}tps?://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1" target=\"_blank\">\\1</a>', $sText);
$sText = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)', '\\1<a href="http://\\2" target=_blank>\\2</a>',
$sText);
$sText = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $sText);
}
}
}
}
}
$Arr = array(
"/\(.+?)\[\/b\]/si",
"/\[i\](.+?)\[\/i\]/si",
"/\[quote=(.+?)\](.+?)\[\/quote\]/si",
"/\[quote\](.+?)\[\/quote\]/si",
"/\[url=(.+?)\](.+?)\[\/url\]/si"
);
$Rep = array(
"<b>$1</b>",
"<i>$1></i>",
"<blockquote>$1 <b>Said</b> <br /> $2</blockquote>",
"<blockquote>$1</blockquote>",
"<a href=\"$1\" target=\"_blank\">$2</a>"
);
$sText = preg_replace ($Arr, $Rep, $sText);
return $sText;
}
}
example usage
require ('Text.class.php');
$oTxt = New TextClass;
$Str = "This is a test [b]string to test the text class out. <br><br> hello there how are you test test test test test test test test test test test test test test test <br><br><br> www.google.com ... http://www.google.com ...emai@eamil.com<BR><BR><BR>";
echo $oTxt->Parse($Str);