Forum Moderators: coopster
my code:
$description = $_POST['description'];
$description = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $description); // turn text links into <a href> links
$description = preg_replace("/\r/", "<br />",$description); // turn line breaks into xhtml br tags
$description = preg_replace("¦<br />\n<br />¦","</p>\n<p>",$description); // turn carriage return-line feeds into xhtml p tags
$description = str_replace("&","&",$description); // turn & into escaped ampersands
$description = str_replace("£","£",$description); // turn £ into escaped pounds
I think textilePHP and PHP markdown do something similar whereby you just include the code file and for every time the code is needed use
Textile(this). In my example I have used
$description = $_POST['foo'] but sometimes $description may need to be derived from e.g. $_POST['bar']
if(function_exists('my_replace'))
{
function my_replace($description)
{
$description = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a href=\"\\0\">\\0</a>", $description); // turn text links into <a href> links
$description = preg_replace("/\r/", "<br />",$description); // turn line breaks into xhtml br tags
$description = preg_replace("¦<br />\n<br />¦","</p>\n<p>",$description); // turn carriage return-line feeds into xhtml p tags
$description = str_replace("&","&",$description); // turn & into escaped ampersands
$description = str_replace("£","£",$description); // turn £ into escaped poundsreturn $description;
}
}
in your php code:
include("function.php");//include the file with the function$description = my_replace($_POST['description']); //call the function
It's elementary my dear Watson...:)
Hope it helps you with the functions
if(function_exists('my_replace'))
I think this may be the problem, it's only defining the function if it exists, so basically your function isn't being defined at all! The correct way should be defining the function if it *doesn't* exist, like so:
if (!function_exists('my_replace'))
So by just adding that exclamation, it should fix your problem.