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:

http://example.com

further reading:

http://php.net/manual/en/function.strstr.php

http://php.net/manual/en/function.explode.php


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -