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
How to write comment in php?
How to check curl is enabled or not in PHP
Write syntax to open a file in php?
What are the steps for the payment gateway processing?
Tell me what does the php error 'parse error in php - unexpected t_variable at line x' means?
What are the advantages of triggers in php?
How to connect to a url in php?
Is polymorphism inherited?
Is session a cookie?
Which cryptographic extension provide generation and verification of digital signatures?
How do I find out the number of parameters passed into function9?
Which of the delimiter is ASP style?
What is string and its function?
Which function Returns the time of sunrise for a given day / location in PHP.
Explain Constant in Class?