Return an array of all matched words
<p>I have a function which replaces any word that looks like a link in a sting in php.</p>
<p>For example</p>
<pre><code>$str = &quot;Please go check out this link http://example.com and http://anothersite.com&quot;;

$link_replace = convert_link($str);

function convert_link($txt){
    $text = preg_replace('/(?i)\b((?:https?:\/\/|[a-z0-9-_]\d{0,3}[.]|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:\'&quot;.,&lt;&gt;?«»“”‘’]))/', '&lt;a href=&quot;$1&quot;&gt;$1&lt;/a&gt;', $txt);
}
</code></pre>
<p>Please I want to only filter the words which are links and put them in an array, so I will have this</p>
<pre><code>$link_array = array('http://example.com', 'http://anothersite.com');
</code></pre>
<p>Please how can I do this?</p>
<h2>Edit</h2>
<p>I tried the <code>preg_match()</code></p>
<pre><code>preg_match('/(?i)\b((?:https?:\/\/|[a-z0-9-_]\d{0,3}[.]|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()&lt;&gt;]+|\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\))+(?:\(([^\s()&lt;&gt;]+|(\([^\s()&lt;&gt;]+\)))*\)|[^\s`!()\[\]{};:\'&quot;.,&lt;&gt;?«»“”‘’]))/', $str, $txt);
print_r($txt);
</code></pre>
<p>But I only get this result</p>
<pre><code>Array(
    [0] =&gt; http://example.com
    [1] =&gt; http://example.com
)
</code></pre>