Rotate text and replace first link

2

I have a variable named $text where it stores texts that the user writes.

  

'$ text="Hahahha that cool this site, I was able to answer all my   questions there link "

'

What do I need?

I have a function named makelink ($ url); which mounts a preview of the content of the link. That is, I need to create a function that will take the FIRST text link and play it in that function, the function will create a preview of the link and will return an output with the HTML result, then of playing the link in the function I need that the output of that goes to the end of the text.

That is:

  

$textfinal = "Hahahha que legal esse site, consegui responder todas minhas perguntas lá https://pt.stackoverflow.com/" *PREVIA DO LINK*

I see as a good alternative to make a filter with regex or something like that (it's not my area) to be able to capture any type of link ..

    
asked by anonymous 30.06.2014 / 16:12

3 answers

1

tries as follows:

$string =  SUA_STRING;
preg_match_all('https?://(([^ .]+)\.)+[^ .]{2,4}(/[^ /]+)', $string, $conteudo);

$link = $conteudo[0][0];//link
    
03.07.2014 / 01:30
1

My dear, you're going to need to use a regular expression to get all the values that start with http or https. It would be something less in this idea:

https?://(([^ .]+)\.)+[^ .]{2,4}(/[^ /]+)*
    
30.06.2014 / 18:10
1

Use the following code:

$links = array();
$text = "Hahahha que legal esse site, consegui responder todas minhas perguntas lá http://pt.stackoverflow.com/"
$regexp = "[-a-zA-Z0-9@:%_\+.~\#?&//=]{2,256}\.[a-z]{2,4}\b(\/[-a-zA-Z0-9@:%_\+.~\#?&//=]*)?";
if(preg_match_all("#$regexp#", $text, $matches, PREG_SET_ORDER)) {
    foreach($matches as $match) {
        $links[] = $match[0];
    }
}

print_r($links);
    
12.08.2014 / 18:33