preg_match_all("~(http://[^ ]+)~", $msg, $urls); //ищу подстроки url for ($i=0; $i< count($urls[0]); $i++) { $msg= str_replace($urls[$i], '<a href="'.$urls[$i].'">'.$urls[$i].'</a>' , $msg); } //пытаюсь заменить их на рабочие с помощью <a> 

But displays on the "Array" in the form of links. What to fix? Can there be any alternative?

    1 answer 1

     $msg= str_replace($urls[0][$i], '<a href="'.$urls[0][$i].'">'.$urls[0][$i].'</a>' , $msg); 

    But generally you have a regular curve) I recommend a resource

    • Can you tell where these second brackets come from? Two-dimensional array? - glarionenko
    • Well, yes) You yourself check count($urls[0]) , i.e. find out the length of the array $urls[0] . Well, just preg_match_all returns a two-dimensional array of the form array[номер_подстроки_в_регулярке][номер_вхождения] . - Sh4dow