shane0714 Posted April 13, 2007 Share Posted April 13, 2007 I have an interesting problem that I have not been able to find the answer to: The purpose of the code below is to search a website and return a name. The name is between the phrase "Owner Name" and "Tax Billing Zip+4". I had to urlencode the information to solve an earlier problem I was having so please don't ask me why I did it that way. I will explain the problem below the code: $taxinfo = urlencode($_POST["taxinfo"]); function getField($s1,$s2,$s){ $L1 = strlen($s1); if($L1>0){$pos1 = strpos($s,$s1);} else {$pos1=0;} if($pos1 !== false){ if($s2 == '') return substr($s,$pos1+$L1); $pos2 = strpos(substr($s,$pos1+$L1),$s2); if($pos2!==false) return substr($s,$pos1+$L1,$pos2); } return ''; } $oname = trim(urldecode(getField("Owner+Name%3A","Tax+Billing+Zip%2B4%3A", $taxinfo))); $onm = explode(" ", $oname); if((strlen($onm[1]) == "1") && (strlen($onm[2]) == "1")) $onm[1] = $onm[1].' '.$onm[2]; elseif((strlen($onm[1]) == "1") && (strlen($onm[2]) > "1")) $onm[1] = $onm[2]; $oname = $onm[1].' '.$onm[0]; Basically, the code above retrieves the owner name from a block of text. That owner name is formatted (last name) (first name) (middle initial or middle name). So, lets say the returned name is "Nobody John Bon". I need to format the name from this to "John Nobody". This is no problem. Sometimes however the name is "Nobody J Bon". In this case, I want it formatted as "Bon Nobody". This is where the problem comes in. If there is an "i" in the middle name, the script fails to return the middle name. So while it has no problem returning "Bon Nobody" in this case, if the middle name was "Michael", it would only return "Nobody". Anybody have any ideas how to fix this? Link to comment https://forums.phpfreaks.com/topic/46862-string-formatting-character-i-messes-it-up/ Share on other sites More sharing options...
shane0714 Posted April 13, 2007 Author Share Posted April 13, 2007 I figured out the problem - it was a simple one of course. I also had a in the code that would set the middle name = "" if it was "jr","sr","i","ii","iii". I just had to add spaces around the "i" to keep it from disrupting whole words. Link to comment https://forums.phpfreaks.com/topic/46862-string-formatting-character-i-messes-it-up/#findComment-228589 Share on other sites More sharing options...
Barand Posted April 13, 2007 Share Posted April 13, 2007 As there is no sign of anything like that in code you posted, I guess you were relying on the telepaths out there to solve that one for you Link to comment https://forums.phpfreaks.com/topic/46862-string-formatting-character-i-messes-it-up/#findComment-228723 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.