Extract url from this string? It should be flexible for all
strings, not for this string only.
"yahoo.comyahoo.co.inhotmail.org"
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 |
Hello Friends,I am seeking for a job in php having 9 months. exp.Please suggest any company openings.
How to find the length of a string?
Tell me what is the definition of a session?
Tell me how can I display text with a php script?
Why many companies are switching their current business language to php? Where php basically used?
How to remove a file?
What is the difference between htmlentities() and htmlspecialchars()?
How can we encrpt a text?
What is the difference between Session and Cookie?
Whether site will complete the execution of the script if Fatal error occurs ?
How can we connect to a mysql database from a php script?
What is php routing?