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)

Might be best to post this in the snippets part

Hehe, I was deciding on whether to do that, would a MOD move it for me?

Thanks allot sir. Been looking for this !!

commented: Nice reply! +1

The eregi functions are deprecated in php 5.3 and since the php development team has officially announced the end of support for php 5.2.x you should update this function to use the preg_ functions instead of ereg.

http://www.php.net/manual/en/ref.pcre.php

mschroeder: I know it is a deprecated function but there are still many people still using eregi_replace. So for that reason, I have decided to leave this as eregi_replace. I May add a new post explaining this same thing with the new function, but I will be posting it as a snippit rather than a post.

Kind Regards
Jack (Scaasiboi)