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.

Link to comment
Share on other sites

<?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;

    }

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.