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 cookie and why do we use it?

0 Answers  


What is a simple php method to make a cross domain data request?

0 Answers  


How to delete file in php?

0 Answers  


Why do we use cookie?

0 Answers  


What does mvc stand for and what does each component do?

0 Answers  






What types of Data Can Be Used as Array Keys?

0 Answers  


Is polymorphism inherited?

0 Answers  


What is difference between count or sizeof function in php?

0 Answers  


This question is regarding version control. If two developers are committing the same php file at same time what will happen ? What error it will show (if any) ?

2 Answers   TCS,


How can we extract string "pcds.co.in" from a string "https://info@pcds.co.in" using regular expression of php? More on reg can you explain

0 Answers  


Explain me difference between mysql_connect and mysql_pconnect?

0 Answers  


What is return value in php?

0 Answers  


Categories