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

How can post form values with out press submit button

5 Answers  


Is there a way to encrypt text from php?

5 Answers  


i got this error msg in online... how to solve this problem... i couldnot find out as soon as possible send me answer or idea COULD NOT ABLE TO CONNECT DATABASE . Can't connect to local MySQL server through socket '/usr/local/mysql-5.0/data/mysql.sock' (2)

3 Answers   Quest,


How do I clear my browser session?

0 Answers  


What is php beginner?

0 Answers  


What is php call function?

0 Answers  


Are php sessions cookies?

0 Answers  


What is the use of array_count_values() in php?

0 Answers  


What is a path Traversal?

0 Answers  


Why print_r is used in php?

0 Answers  


How do you debug php?

0 Answers  


Explain what is memcache?

0 Answers  


Categories