Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

Is runtime polymorphism overriding?

0 Answers  


What are psrs? Choose 1 and briefly describe it?

0 Answers  


How can I know that a variable is a number or not using a JavaScript?

2 Answers  


Can you define an array argument as a reference type?

0 Answers  


Explain how can we execute a php script using command line?

0 Answers  


Which programming language does php resemble to?

0 Answers  


How can we get the browser properties using PHP?

7 Answers  


How do I check if a given variable is empty?

0 Answers  


How to convert a string to lowercase in php?

0 Answers  


What is the correct line to use within the php.ini file, to specify that 128mb would be the maximum amount of memory that a script may use?

0 Answers  


Explain what is the use of "echo" in php?

0 Answers  


What is the use of friend function?

7 Answers   Wipro,


Categories