Welcome to WebmasterWorld Guest from 54.163.168.15

Forum Moderators: coopster & jatar k

remove www. only if it exists

   
3:05 pm on Oct 2, 2009 (gmt 0)

5+ Year Member



I have an list/array of URL's that are going to be stored in a DB:

example1.com
www.example2.com
example3.org
example4.net
www.example6.edu

How would I parse the URLs so that the "www." is removed from any domains that contain it, and the rest of the domains are not modified. The results should look like:

example1.com
example2.com
example3.org
example4.net
example6.edu

3:40 pm on Oct 2, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You would probably use something like str_replace() or substr_replace() depending on your exact application... If you need to replace all sub domains, not just www you would probably have to graduate to preg_replace and stay away from ereg_replace it runs on a different regex engine than preg_replace and isn't anywhere near as fast.

[us2.php.net...]
[us2.php.net...]

4:01 pm on Oct 2, 2009 (gmt 0)

5+ Year Member



Figured it out, thanks!
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month