Jump to content

how to wrap a url which is in the string with href tag?


caballero

Recommended Posts

Howdy,

 

I'm in trouble here. Does someone know how to wrap a url which is in the string with href tag without writing like a few hundred line long code? Example:

Before: "This is a url http://www.domain.com and then some text"

After: "This is a url <a href="http://www.domain.com">http://www.domain.com</a> and then some text"

 

:confused:

 

the string is to be received by a flash application right after.

<?php

function replace_links($string){

$start = strpos($string, 'http://');

    if($start !== false){

        $end = strpos($string, " ",$start);

        $link = substr($string, $start,$end-$start);

        $link = "<a href='$link'>".$link."</a>";

        return substr_replace($string,$link,$start,$end-$start);

    }else{

        return $string;

    }

}

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.