Hi!
does anyone have an idea how to parse a textstring for links... it should look for strings starting with "http://..." and end with an spacer " "... and these should be replaced by an <a href=...</a>
I have no idea how to start... maybe someone has done st similar... ?
Read the PHP manual about preg_match(), ereg_match() and preg_replace()
Well, it seems to be the right way, but it converts the string a bit strange...
my test-text was: "link1 is http://www.link1.de and link2 is http://www.link2.de and more text"
and the link-string I received was: "link1 is <A HREF="$1">$1<\/A>text"
I have no idea why it just converts 1 string... and why it replaces the link with $1...
I am sorry too...maybe I am too stupid, but it still doesnt work...
$links = preg_replace("/(http:\/\/.*)\s/i","<A HREF=\"$1\">$1</A>",$text);
thats whats in my script now... and it turns this text:
link1 is http://www.link1.de and link2 is http://www.link2.de and more text
into: link1 is <A HREF="$1">$1</A>text
For those who are still interested... here is the solution:
$matschi="/(http:\/\/([a-z0-9]+.){2,}[a-z0-9]+)\s+/";
$links = preg_replace("$matschi","<A HREF=\"\1\">\1</A> ",$text);
This script works 100%... i just tested it...
This should work
$var = preg_replace("/(http:\/\/.*)\s/i","<A HREF=\"\1\">\2</A>",$var);
use \1 and \2 instead of $1, $2
\1... is regex argument number - the things keep in parenthesises 🙂