ArizonaJohn Posted June 26, 2009 Share Posted June 26, 2009 Hello, My site allows users to enter URLs into a database. I am using the code "$site = strtolower($site);" to make all of these URLs lower-case. However, I just realized that Wikipedia URLs are case sensitive, so I would like to avoid using "$site = strtolower($site);" on Wikipedia URLs, all of which contain "wikipedia.org". How could I write a function that will skip over the step "$site = strtolower($site);" if $site contains "wikipedia.org"? Thanks in advance, John Quote Link to comment https://forums.phpfreaks.com/topic/163714-function-to-skip-strtolower-if-variable-contain-wikipediaorg/ Share on other sites More sharing options...
ldougherty Posted June 26, 2009 Share Posted June 26, 2009 if (!strpos($site,'wikipedia.org')) { $site = strtolower($site); } so essentially it says if wikipedia.org is not found in the string to lower case the string. Quote Link to comment https://forums.phpfreaks.com/topic/163714-function-to-skip-strtolower-if-variable-contain-wikipediaorg/#findComment-863834 Share on other sites More sharing options...
Alex Posted June 26, 2009 Share Posted June 26, 2009 if(strpos($site, 'wikipedia.org') === false) { $site = strtolower($site); } Quote Link to comment https://forums.phpfreaks.com/topic/163714-function-to-skip-strtolower-if-variable-contain-wikipediaorg/#findComment-863835 Share on other sites More sharing options...
Ken2k7 Posted June 26, 2009 Share Posted June 26, 2009 if (!strpos($site,'wikipedia.org')) { $site = strtolower($site); } so essentially it says if wikipedia.org is not found in the string to lower case the string. Try that with - $site = 'WIKIPEDIA.ORG is all in caps!'; Quote Link to comment https://forums.phpfreaks.com/topic/163714-function-to-skip-strtolower-if-variable-contain-wikipediaorg/#findComment-863865 Share on other sites More sharing options...
.josh Posted June 26, 2009 Share Posted June 26, 2009 so use stripos instead. Or, if you do not have php5, use some good old fashioned regex: if(!preg_match('~wikipedia\.org~i',$string)) { $string = strtolower($string); } Quote Link to comment https://forums.phpfreaks.com/topic/163714-function-to-skip-strtolower-if-variable-contain-wikipediaorg/#findComment-863867 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.