How to match a pattern and store it in an array using preg_match
I want to search for url in a string and store them in an array.
This seems easy, but I can't seem to find a way to do it. I think it might be similar to using preg_replace?
$myarray = preg_replace(
"/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",
null, $input)
For example, my input line is
$input = "
blah blah blah https://www.google.com
blah blah blah https://www.yahoo.com
blah blah blah http://stackoverflow.com"
Finally, the result should be the values โโof the three references matched in the array.
$myarray[0] = "https://www.google.com"
$myarray[1] = "https://www.yahoo.com"
$myarray[2] = "https://stackoverflow.com"
I hope you understand my desire and are sorry if something is not clear.
+3
source to share