Jump to content

Recommended Posts

Hi all,

 

Is the following a substr function PHP bug?  This is also happening with regex functions.

 

$EmailLogFull["Content"] = "mail(\"Firstname Lastname\" <myemail@dummy.com>, 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

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

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>"; ?>

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.