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
What are php expressions?
Can the value of a constant change during the script's execution?
Can we override static method?
Write a program to get second highest number in an array using php?
Is it more secure to use cookies to trfer session ids?
How do sessions work in php?
What is varchar mysql?
Is null or empty c#?
How to list all values of submitted fields?
What is the difference between static and dynamic websites?
What does the expression exception::__tostring means?
What is a composer in PHP?
Are php variables global?
What is the use of return in php?
Which of the data type is compound datatype supported by PHP?