Jump to content

String Formatting - character "i" messes it up


shane0714

Recommended Posts

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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.