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

Is php a dying language?

539


What is php array function?

543


Tell me how can we display information of a variable and readable by human with php?

567


What is move_uploaded_file in php?

553


Tell me how is it possible to parse a configuration file?

505






What is encapsulation in php with example?

558


How do you compare strings in java?

517


How to delete cookie files on your computer?

551


How do you remove duplicates from an array?

662


Explain about require and include function?

570


Tell me what is the definition of a session?

553


How can you declare the array in php?

522


How long does a session last in php?

514


Write a hello world program using variable?

539


How can we check the value of a given variable is a number?

610