#35985 [NEW]: strpos() or substr() function or $variable or echo doesn't work properly.
| From: | scott at abcoa dot com | Date: | Thu, 12 Jan 2006 20:19:15 +0000 |
| Subject: | #35985 [NEW]: strpos() or substr() function or $variable or echo doesn't work properly. | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-91809@lists.php.net to get a copy of this message | ||
From: scott at abcoa dot com
Operating system: AIX 5.2
PHP version: 5.1.2
PHP Bug Type: Variables related
Bug description: strpos() or substr() function or $variable or echo doesn't work properly.
Description:
------------
After some hair pulling over figuring out the problem was until I came
upon this bug and built a testcase for it. The script I'm using is a
screen scraping feature since one of the Credit Bureaus doesn't have XML
data. This bug was detected 2 months ago with PHP 4.3.7 then upgraded PHP
5.1.1 and bug still exist.
The bug here is that there's no "<td>" data in PHP but is present when it
is passed on to HTML. I don't know if the bug is the echo, substr() or
strpos(). So, pay attention to the $ssn1 variable via echo output.
Reproduce code:
---------------
<?
//$responsedata =
"<table><tr><td>SSN:</td><td>400-41-4001</td></table>";
$responsedata =
"<table><tr><td>SSN:</td><td>400-41-4001</td></table>";
//$StrPosValue3 = 0;
for($x=0;$x<2;$x++) { //1 - Individual, 2 - Joint
$StrPosValue1 = strpos($responsedata,"SSN:",$StrPosValue3);
if (!($StrPosValue1 === false)) {
$StrPosValue1 = strpos($responsedata,"<td>",($StrPosValue1+1));
$tmp1 = substr($responsedata,0,$StrPosValue1+4);
$tmp2 =
substr($responsedata,$StrPosValue1,strlen($responsedata));
$StrPosValue2 = strpos($tmp2,"</td>");
$ssn1 = substr($tmp2,0,$StrPosValue2);
$tmp3 = substr($tmp2,$StrPosValue2,strlen($tmp2));
$ssn1 = trim($ssn1);
$ssn1 = str_replace("-","",$ssn1);
//12/23/2005 - Found a PHP bug that somehow insert the \"<td>\"
characters to the beginning of
// the SSN characters, problem is it is not visisible
with the echo command unless
// it is assigned to a variable or to this, echo "test
".$ssn1." test"; statement...
// So, we'll have to use PHP to remove it ourselve...
//=============================================
//=============================================
// See bug demo below...
echo "## --> ".$ssn1." <-- ##<br>";
echo "<script type='text/javascript'>\n";
echo "alert('".$ssn1."');\n";
echo "</script>\n";
//=============================================
//=============================================
// Bug workaround available below...
$ssn1 = substr($ssn1,-9); //Used the last 9 characters and dump
the first 4 characters...
//=============================================
//=============================================
$ssn1 = "XXX-XX-".substr($ssn1, -4);
$responsedata = $tmp1.$ssn1.$tmp3;
$StrPosValue3 = $StrPosValue1 + 1;
}
}
?>
Expected result:
----------------
Should not display the "<td>" data.
Actual result:
--------------
Displayed the "<td>" data.
--
Edit bug report at http://bugs.php.net/?id=35985&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=35985&r=trysnapshot44
Try a CVS snapshot (PHP 5.1): http://bugs.php.net/fix.php?id=35985&r=trysnapshot51
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=35985&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=35985&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=35985&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=35985&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=35985&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=35985&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=35985&r=support
Expected behavior: http://bugs.php.net/fix.php?id=35985&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=35985&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=35985&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=35985&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=35985&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=35985&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=35985&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=35985&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=35985&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=35985&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=35985&r=mysqlcfg