Page 1 of 1

[SOLVED] Strpos() not detecting less than character (<)

Posted: Tue Mar 27, 2007 9:01 am
by impulse()
I have an array which contains the parse of an e-mail address from a .EML file. Each element looks like the following:


1) "'Namea'"<Namea@x.com>
2) "'Nameb'"<Nameb@x.com>
3) "'Namec'"<namec@entagroup.com>

I want to extract the e-mail address from each of those elements so I have the following code:

Code: Select all

foreach($toSplit as $a) {

          $b[$i]      = str_replace(" ", "", $a);
          $start[$i]  = strpos("<", $b[$i]);
          $end[$i]    = strpos(">", $b[$i]);
          $output[$i] = substr($b, $start[$i], $end[$i]);
          $i++;

        }
But the $start nor $end elements are being filled.

Any idea for this?

Regards,

Posted: Tue Mar 27, 2007 9:05 am
by feyd
Are you sure they are not in another form such as HTML entity?

Posted: Tue Mar 27, 2007 9:11 am
by impulse()
I've checked the HTML source and it doesn't seem so. I've tried this code (which I think should work correctly):

Code: Select all

foreach($toSplit as $a) {

          $b[$i]      = str_replace(" ", "", $a);
          $start[$i]  = strpos(html_entity_decode("<", $b[$i]));
          $end[$i]    = strpos(html_entity_decode(">", $b[$i]));
          $output[$i] = substr($b[$i], $start[$i]);
          $i++;

        }
But I still have the same results.

Posted: Tue Mar 27, 2007 9:44 am
by impulse()
THis is quite embarrasing - I was using print_r to show all the data but because each element was wrapped with "<" & ">" the browser was treating them as HTML tags and not outputting the data. At some point it wasn't outputting the HTML source, but that must of been at a point where there was an error :D

I have learned about HTML entities though so it's not all bad.

Posted: Tue Mar 27, 2007 9:45 am
by Xoligy
Why not use REGEXP?

Posted: Tue Mar 27, 2007 9:47 am
by impulse()
I hate RegExp, I've read a bit about it and I've never liked it from day 1. I'll only learn how to use it when it's the only way to do something. In the meantime I'm quite happy without it.

End code by the way:

Code: Select all

foreach($toSplit as $a) {

          $b[$i]       = str_replace(" ", "", $a);
          $start[$i]   = strpos($b[$i], "<");
          $end[$i]     = strpos($b[$i], ">");
          $output[$i]  =  substr($b[$i], $start[$i], $end[$i]);
          $output[$i]  = ltrim($output[$i], "<");
          $output[$i]  = rtrim($output[$i], ">");
          $i++;

        }