Bilal Halayqa Bilal Halayqa - 1 month ago 5
PHP Question

Remove "www." from domain name string

How do I remove "www." from the url if it comes in the beginning only.

www.google.com --> google.com


I have tried the following so far, but this removes the "www." if it is in any place :

str_ireplace('www.','',$parsed_url);


Thanks in advance.

Answer Source
$a = "www.google.com";
echo preg_replace ("~^www\.~", "", $a);