0
I’m taking texts from my database, I wanted to know, if there is a link inside this text, how do I make it appear as a normal link for everyone?
0
I’m taking texts from my database, I wanted to know, if there is a link inside this text, how do I make it appear as a normal link for everyone?
2
Basically you will need to replace
~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~
$texto = "Oi, sou Mauro, costumo acessar vários sites como http://www.facebook.com";
$texto = preg_replace(
"~[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]~",
"<a href=\"\\0\">\\0</a>", $texto
);
echo $texto;
See in operation: http://sandbox.onlinephpfunctions.com/code/15e9d2a36e35ef396e4fd54fbdb4efaffa68890d
If you don’t want to reinvent the wheel, there are some libs
who do this work for you, these are the ones I use/used and recommend.
Browser other questions tagged php html5
You are not signed in. Login or sign up in order to post.
There are two questions: "I wanted to know, if there is a link inside this text" Can’t you see? Second: "how do I make it appear as a normal link" To know if there is a link. Just view the text. The link within an X text can come in the following ways: http://www or <a href="http://". Would that be more or less what you want? Are there html tags? If yes, edit your question and enter the text/code blocks.
– Fabiano Monteiro