zeddeh Posted February 12, 2007 Share Posted February 12, 2007 Hello all, I am trying to fix a capitalization issue since some of the database last names are non-standard: MacDonald, or van Berg, Wolfe-Milner, etc. I have got the Mc... and the Mac... working ok and made a line for Jr. (see code below) but then when I put in another section to change the code for Wolfe-Milner the Mc and Mac's now revert to lower case and only the Wolfe-Milner section works. It seems to only recognize the last bit of code and ignores the first ones. I am perplexed as to what is in the Wolfe-Milner code that is causing the first 2 sections to be ignored. Any ideas? Many thanks! -------- start code ------- //Fix internal capitalization $lastName_temp = strtolower($data_array[$i][1]); $pos = strpos($lastName_temp,"mc"); if($pos === 0) { $lastName_temp = substr($lastName_temp,2); $lastName_temp = "Mc".ucfirst($lastName_temp); }else{ $lastName_temp = ucfirst(strtolower($data_array[$i][1])); } $lastName_temp = strtolower($data_array[$i][1]); $pos = strpos($lastName_temp,"mac"); if($pos === 0) { $lastName_temp = substr($lastName_temp,3); $lastName_temp = "Mac".ucfirst($lastName_temp); }else{ $lastName_temp = ucfirst(strtolower($data_array[$i][1])); } $lastName_temp = strtolower($data_array[$i][1]); $pos = strpos($lastName_temp,"wolfe-"); if($pos === 0) { $lastName_temp = substr($lastName_temp,6); $lastName_temp = "Wolfe-".ucfirst($lastName_temp); }else{ $lastName_temp = ucfirst(strtolower($data_array[$i][1])); } $lastName_temp = str_ireplace(" jr"," Jr",$lastName_temp); Quote Link to comment Share on other sites More sharing options...
effigy Posted February 12, 2007 Share Posted February 12, 2007 Before each check you re-read the variable from its original source, thus losing the changes you made before. $lastName_temp = strtolower($data_array[$i][1]); This might be easier for you: <pre> <?php $tests = array( 'mcdonald', 'macdonald', 'ronald mcdonald', 'ronald macdonald', 'bob wolfe-johnson', 'howard harrison, jr.', 'howard harrison, jr', ); foreach ($tests as $test) { echo $test, ' => '; $test = preg_replace('/\b((?:ma?c)|(?:wolfe-)|(?:jr\.?\b))/e', 'ucfirst("\1")', $test); echo $test, '<br>'; } ?> </pre> Quote Link to comment Share on other sites More sharing options...
zeddeh Posted February 12, 2007 Author Share Posted February 12, 2007 Hmmm, yes I figured I might be doing something like that. Welcome to my world of the inexperienced. Your code sure is a lot more compact, I will give it a try and also try to look at it more deeply to see how it works as I will need to edit it to include more names also. Many thanks Zeddeh Quote Link to comment Share on other sites More sharing options...
Balmung-San Posted February 12, 2007 Share Posted February 12, 2007 Hmmm, yes I figured I might be doing something like that. Welcome to my world of the inexperienced. Your code sure is a lot more compact, I will give it a try and also try to look at it more deeply to see how it works as I will need to edit it to include more names also. Many thanks Zeddeh In that case you'll want to look at http://www.regexp.info. effigy's code relies heavily on a regular expression (which is a good thing), so without understanding it you can't add more on. Quote Link to comment Share on other sites More sharing options...
zeddeh Posted February 12, 2007 Author Share Posted February 12, 2007 Thanks Balmung-San, I will take a look there and do some learning... Cheerio Zeddeh Quote Link to comment 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.