I've seen over the last few days many people on the internet and various forums asking for how this is done.
Now there is plenty of posts out there that explain how to do this.
However I have yet to find one that explains how you work it into a MYSQL string.
So here is a how-to for you.
Your normal function for eregi_replace is untouched.
function makeClickableLinks($text) {
$text = eregi_replace('(((f|ht){1}tp://)[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'<a href="\\1">\\1</a>', $text);
$text = eregi_replace('([[:space:]()[{}])(www.[-a-zA-Z0-9@:%_\+.~#?&//=]+)',
'\\1<a href="http://\\2">\\2</a>', $text);
$text = eregi_replace('([_\.0-9a-z-]+@([0-9a-z][0-9a-z-]+\.)+[a-z]{2,3})',
'<a href="mailto:\\1">\\1</a>', $text);
return $text;
}
It is important to check the example above, many tutorials online show this function without RETURN but instead have ECHO, this will not work with what we are doing here.
So, you have your function, now lets take a look at an example MYSQL string for inputting data into a table.
$sql="INSERT INTO news (title, date, news) VALUES('$_POST[title]','$storydate','$echocommand')";
The above features a normal typical MYSQL string.
All we are going to do is pass the variable along so that it can be seen by SQL.
After your function you need to add the following:
$text = (WHATEVER YOU WANT CONVERTING HERE);
This code will assign what ever you want converting to the variable $text.
Next we will create the $echocommand as seen above. This is most definitely not rocket science and is done like this:
$echocommand = makeClickableLinks($text);
Now you can call $echocommand from within your MYSQL string as done above.
This really is a straight forward thing to do, but it doesn't seem to ever be mentioned when explaining the eregi_replace function.
Hope this helps someone somewhere!
Kind Regards,
Jack (Scaasiboi)