Mateo1041 Posted February 1, 2008 Share Posted February 1, 2008 Hi all, Is the following a substr function PHP bug? This is also happening with regex functions. $EmailLogFull["Content"] = "mail(\"Firstname Lastname\" <[email protected]>, this is a test"; $pos1 = strpos($EmailLogFull["Content"], "mail(") + strlen("mail("); $pos2 = strpos($EmailLogFull["Content"], ","); $result = substr($EmailLogFull["Content"], $pos1, $pos2 - $pos1); Basically, I'm looking to extract the email address from the above string. But it keeps removing the email address portion due to what I assume is the "<" character. Anyone have any ideas? Thanks much, - Matt Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/ Share on other sites More sharing options...
btherl Posted February 1, 2008 Share Posted February 1, 2008 I tried that code you posted, and it works fine. Perhaps the error is elsewhere in your code? Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-455054 Share on other sites More sharing options...
Mateo1041 Posted February 1, 2008 Author Share Posted February 1, 2008 This is an exact copy of the code. I also pasted this same code into a separate stand-alone PHP file and have the same problem. I'm displaying the $result this way: echo "<h3>" . $result . "</h3>"; All I'm getting is this with no email address: "Firstname Lastname" http://data.bluegoose.org/test.php Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-455257 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 Your code works fine, but the browser is treating the email as an HTML tag because it's in <...>. You need to wrap $result with htmlspecialchars() and you should be good to go. <?php echo "<h3>" . htmlspecialchars($result) . "</h3>"; ?> Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-455261 Share on other sites More sharing options...
Mateo1041 Posted February 1, 2008 Author Share Posted February 1, 2008 Thank you! That worked. Now why a browser would treat a non-tag as a tag is beyond me. Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-455293 Share on other sites More sharing options...
rhodesa Posted February 1, 2008 Share Posted February 1, 2008 the browser treats anything between <...> as a tag. so, you need to use < and > instead, and that php function does that replacement for you. Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-455298 Share on other sites More sharing options...
btherl Posted February 3, 2008 Share Posted February 3, 2008 The reason anything between <> must be treated is a tag is that HTML is designed to be backwards compatible. That is, an old HTML parser must be able to ignore newer HTML tags invented later. So if it finds a tag it doesn't know, it will assume that it's a tag from some future version of HTML, and skip it. Link to comment https://forums.phpfreaks.com/topic/88840-php-substr-bug-when-parsing-an-email-address/#findComment-456624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.