php function to extract link from string
<p>i want to extract href link from text or string. i write a little function to do that but this is slow when a string to transform is large. My code is</p>

<pre><code>function spy_linkIntoString_Format($text) {
    global $inc_lang; $lang = $inc_lang['tlang_media'];
    $it = explode(' ' ,$text);
    $result = '';
    foreach($it as $jt) {
        $a = trim($jt);
        if(preg_match('/((?:[\w\d]+\:\/\/)?(?:[\w\-\d]+\.)+[\w\-\d]+(?:\/[\w\-\d]+)*(?:\/|\.[\w\-\d]+)?(?:\?[\w\-\d]+\=[\w\-\d]+\&amp;?)?(?:\#[\w\-\d]*)?)/', $jt)) {
            $pros_lis = str_replace('www.','',$jt);
            $pros_lis = (strpos($pros_lis, 'http://') === false ? 'http://'. $pros_lis : $pros_lis);
            $urlregx = parse_url($pros_lis);
            $host_name = (!empty($urlregx['host']) ? $urlregx['host'] : '.com');
            if($host_name == 'youtube.com') {
                $string_v = $urlregx['query']; parse_str($string_v, $outs); $stID = $outs['v'];
                $result .= '&lt;a title="Youtube video" coplay="'.$stID.'" cotype="1" class="media_spy_vr5" href="#"&gt;&lt;span class="link_media"&gt;&lt;/span&gt;'.$lang['vtype_youtube'].'&lt;/a&gt; ';
            } elseif($host_name == 'vimeo.com') {
                $path_s = $urlregx['path']; $patplode = explode("/", $path_s); $stID = $patplode[1];
                $result .= '&lt;a title="Vimeo video" coplay="'.$stID.'" cotype="2" class="media_spy_vr5" href="#"&gt;&lt;span class="link_media"&gt;&lt;/span&gt;'.$lang['vtype_vimeo'].'&lt;/a&gt; ';
            } elseif($host_name == 'travspy.com') {
                $result .= '&lt;a href="'.$jt.'" title="'.$pros_lis.'" &gt;&lt;span class="jkt_445 jkt_3256 c8_big_corner"&gt;&lt;/span&gt;'.$pros_lis.'&lt;/a&gt; ';
            } else {
                $result .= '&lt;a href="'.$jt.'" title="'.$pros_lis.'" rel="nofollow" target="_blank"&gt;&lt;span class="jkt_445 c8_big_corner"&gt;&lt;/span&gt;'.$pros_lis.'&lt;/a&gt; ';
            }
        } else {
            $result .= $jt.' ';
        }
    }
    return trim($result);/**/
}
</code></pre>

<p>Can i do this run fast?</p>
