Extract url from this string? It should be flexible for all
strings, not for this string only.
"yahoo.comyahoo.co.inhotmail.org"

Answer Posted / amitverma

##
##This will work for PHP 5.3 -

$url1="yahoo.com";
$url2="yahoo.co.in";
$url3="hotmail.org";

$domain1 = strstr($url1, '.', true);
$domain2 = strstr($url2, '.', true);
$domain3 = strstr($url3, '.', true);

echo $domain1, $domain2, $domain3;


##
## For Older PHP (<5.2.8), this code will follow -
$url1="yahoo.com";
$url2="yahoo.co.in";
$url3="hotmail.org";

$domain1 = substr($url1, 0, strpos($url1, '.') );
$domain2 = substr($url2, 0, strpos($url2, '.') );
$domain3 = substr($url3, 0, strpos($url3, '.') );

echo $domain1, $domain2, $domain3;


Is This Answer Correct ?    2 Yes 8 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of extract function in php?

504


What are the functions for imap?

586


What is php pathinfo?

577


Php says that an array is an ordered map. But how the values are ordered in an array?

591


What is properties of class?

583






What is difference between core php and framework?

456


What is baseurl?

528


Which parts of php are case sensitive?

486


How to concatenate two strings together in php?

558


Please explain is it possible to use com component in php?

547


What is difference between post and put in rest?

507


How do you use bcrypt for hashing passwords in php?

525


What function do we use to find length of string, and length of array?

525


What is var_dump function in php?

526


What is the php function that removes the first element of the array and returns it?

500