Page 1 of 1

[SOLVED] strpos and substr not giving expected results

Posted: Wed Mar 21, 2007 5:09 am
by impulse()
I'm parsing an e-mail using a MIME parser from phpclasses.org and then inserting the data into a MySQL database. But because some of the e-mail have more than 1 delivery address the output is as follows:

"'Mr A'" <a@x.com>,
"'Mrs B'" <b@x.com>,

So far I have exploded all the data by " which has left me with lines of the following:

'A'

,

'B'

,

Then I've used the following code to go through each line and find the first ' and the 2nd ' and then use substr to put everything inbetween into another variable, using the following code.

Code: Select all

$toSplit = explode("\"", $toInsert);

foreach($toSplit as $a) {
  $start[$i] = strpos($a, "\"");
  $end[$i]   = strpos($a, "\"", $start[$i]);
  $out[$i]   = substr($a, $start[$i], $end[$i]);
  $i++;
}
But this doesn't print any data out. Strpos doesn't seem to be finding the start and end occurences of the speech marks.

Can anybody see why in this example?

Regards,

Posted: Wed Mar 21, 2007 5:43 am
by impulse()
I've used the following code:

Code: Select all

$toSplit = explode("\"", $toInsert);

        $i = 0;

        foreach($toSplit as $a) {
          $out[$i] = trim($a, "\'");
          $i++;

        }

        $toInputDB = "";
        foreach($out as $a) {
          $toInputDB .=  strip_tags($a). " ";
        }