Article 5CZW1 PHP "preg_replace" issue

PHP "preg_replace" issue

by
TBotNik
from LinuxQuestions.org on (#5CZW1)
All,

Processing a file with strings of:
  1. Company Name
  2. URL
  3. City
  4. State
Using the code:
Code: $oline = preg_replace('!\s\s+!', ', ', $line);
$r_ray = explode(", ", $oline);Which works most of the time, but sometimes the "State" does not parse, but stays in $r_ray[2], leaving $r_ray[3] blank or empty!

Can I fix my preg_replace to always work or do I need an "if" statement to check for blank/empty $r_ray[3]?

Example Failed Output:
Input:
Code:Binary Capital http://www.binarycap.com/ San Francisco CAOutput:
Code:Array
(
[0] => Binary Capital
[1] => http://www.binarycap.com/
[2] => San Francisco CA

)The proper working would always put the state, "CA" in this case, into $r_ray[3]. This is working over 75% of the time and not understanding why the anomalies.

I'm processing this file to create MySQL "INSERT" statements to process into my DB. Want the SQL to be correct!

All help appreciated!

Cheers!

TBNKlatest?d=yIl2AUoC8zA latest?i=vXVDMRg2S1s:RIjhfdyyx48:F7zBnMy latest?i=vXVDMRg2S1s:RIjhfdyyx48:V_sGLiP latest?d=qj6IDK7rITs latest?i=vXVDMRg2S1s:RIjhfdyyx48:gIN9vFwvXVDMRg2S1s
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments