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



Extract url from this string? It should be flexible for all strings, not for this string only. &q..

Answer / 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

More PHP Interview Questions

What is rtrim php?

0 Answers  


How to remove duplicate values from php array?

0 Answers  


hi, i am new for php I want to know where to create & how to run phpscript programme in LAMP?

2 Answers  


How to specify argument default values?

0 Answers  


What is the use of "ksort" in php?

0 Answers  






Why using the htaccess file

2 Answers  


In php how can you jump in to and out of "php mode"?

0 Answers  


Shopping cart online validation i.e. how can we configure Paypal, etc.?

1 Answers   INDUS,


How can you compare objects in php?

0 Answers  


What language is similar to php?

0 Answers  


How does csrf token work?

0 Answers  


Is runtime polymorphism overriding?

0 Answers  


Categories