php - Get all words or urls with 'www' on a given text -


i need words or urls 'www' on given text. tried far.

<?php  $needle = 'www'; $sentence = 'this www.google.com http://www.facebook.com website https://www.amazon.com make me awesome';  echo $needle . "<br />"; echo $sentence . "<br /><br />";  if(preg_match('/\b(' . preg_quote($needle, '/') . '\w+)/', $sentence, $match)){     echo "<pre>";         print_r($match);     echo "</pre>"; } ?> 

the output i'm expecting array of values:

www.google.com http://www.facebook.com  https://www.amazon.com 

but currently, code not work , output blank array. please me solve this. thanks.

try believe desired result

$sentence = 'this www.google.com http://www.facebook.com website https://www.amazon.com make me awesome'; $pattern = '@((https?://)?([-\\w]+\\.[-\\w\\.]+)+\\w(:\\d+)?(/([-\\w/_\\.]*(\\?\\s+)?)?)*)@';  preg_match_all($pattern, $sentence, $matchfound);  echo '<pre>'; print_r($matchfound[0]); 

output

array (   [0] => www.google.com   [1] => http://www.facebook.com   [2] => https://www.amazon.com ) 

Comments

Popular posts from this blog

ZeroMQ on Windows, with Qt Creator -

unity3d - Unity SceneManager.LoadScene quits application -

python - Error while using APScheduler: 'NoneType' object has no attribute 'now' -