Extracting url from string php -
i trying extract url out of string. format of string be:
some text! numbers http://linktoimage.com/image
i found post earlier extract urls text in php
and think solution mentioned there work:
<?php $string = "this friend's website http://example.com think coll"; echo explode(' ',strstr($string,'http://'))[0]; //"prints" http://example.com
however not understand does. mind explaining me me ?
you have string:
this friend's website http://example.com think coll
strstr($string,'http://')
return
http://example.com think coll
explode(' ', ...)
split resulting string @ space character resulting in
array( 0 => 'http://example.com', 1 => 'i', 2 => 'think', 3 => 'it', 4 => 'is', 5 => 'coll' )
and [0]
returns first item of array, is:
further reading:
Comments
Post a Comment