homepage Welcome to WebmasterWorld Guest from 54.197.15.196
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
remove www. only if it exists
martymac

5+ Year Member



 
Msg#: 3999960 posted 3:05 pm on Oct 2, 2009 (gmt 0)

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

 

jd01

WebmasterWorld Senior Member 5+ Year Member



 
Msg#: 3999960 posted 3:40 pm on Oct 2, 2009 (gmt 0)

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...]

martymac

5+ Year Member



 
Msg#: 3999960 posted 4:01 pm on Oct 2, 2009 (gmt 0)

Figured it out, thanks!

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved