How to extract or fetch urls from text in PHP?

How to show url as a link from a text in php.
this code will return you the link from a text .
simply copy and paste this in you php file and call the function.


 <?php
            function make_clickable_string_url($text) {
            return preg_replace_callback(
            '#\bhttps?://[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|/))#',
            create_function(
            '$matches',
            'return "<br/><a href=\'{$matches[0]}\'>{$matches[0]}</a>";'
            ),
            $text
            );
            }
        ?>

it will return you the string as well as return a link of url which exist in content

Comments