Bug #71634 [NEW]: String functions can't work with (purported) integer extracted from string
| From: | 4OtherBusiness at comcast dot net | Date: | Fri, 19 Feb 2016 19:46:17 +0000 |
| Subject: | Bug #71634 [NEW]: String functions can't work with (purported) integer extracted from string | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199350@lists.php.net to get a copy of this message | ||
From: 4OtherBusiness at comcast dot net
Operating system: Windows 7 Enterprise w/ SP 1
PHP version: 5.6.18
Package: *General Issues
Bug Type: Bug
Bug description:String functions can't work with (purported) integer extracted from string
Description:
------------
Actually I'm using 5.6.14
* Source is text file, that I've done the notepad be-sure-it's-text
exercise with.
* Earlier I run my functions which scanned it and filled array $input
with integers and text, all computed from the raw HTML.
I've tried:
* Modifying raw HTML that it scans
* Renaming variables
* intval() and settype($mystring,"integer") and mathematics
Using settype() and later chunk_split() showed me that it's not
substr(), as I originally thought, but the content of my variable.
It looks like an integer, but it won't work w/ string functions.
FORTUNATELY it does work with a for loop.
Test script:
---------------
//
===========================================================================================
// For <select>
function clearSelected(&$lines, $ele_no, $input, $opt_no_or_all)
{
if (strtolower($opt_no_or_all) != "all")
{
$opt_no=$opt_no_or_all ;
$line_no=$input[$ele_no]['parts'][$opt_no]['selected']['line_no']
;
$line=$lines[$line_no] ;
$NcharB4=$input[$ele_no]['parts'][$opt_no]['selected']['chars_before']
;
echo "Just extracted: \$NcharB4=".$NcharB4."\n" ;
$chars_before=intval($NcharB4) ;
echo "Integer val: \$chars_before=".$chars_before."\n"
;
$chars_before=$chars_before * 1 -1+1;
echo "After some math: \$chars_before=".$chars_before."\n"
;
// The code below replaces bizarre $chars_before not working
in string functions
$front=""; for ($i=0;$i<$chars_before;$i++) {$front =
$front.substr($line,$i,1) ;}
echo "\$line=".htmlspecialchars($line) ;
echo "\$chars_before=".$chars_before."\n" ;
if (!is_null($chars_before) && !$chars_before=0)
{
$front=chunk_split($line,$chars_before) ;
$back=mb_substr($line, $chars_before+8) ;
echo "\$front=".htmlspecialchars($front)."\n" ;
echo "\$back=".htmlspecialchars($back)."\n" ;
$lines[$line_no]=$front.$back ;
}
}
else
{
$nbr_opt=count($input[$ele_no]['parts']) ;
for($opt_no=0;$nbr_opt-1; $opt_no++)
{
$line_no=$input[$ele_no]['parts'][$opt_no]['selected']['line_no']
;
$line=$lines[$line_no] ;
$cbefore=$input[$ele_no]['parts'][$opt_no]['selected']['NcharB4']
;
if (!is_null($cbefore) && !$cbefore==0)
{
$front=substr($line, 0, $cbefore) ;
$back=substr($line, $front+8+1) ;
$lines[$line_no]=$front.$back ;
}
}
} // EO else "all" or not
return ;
}
Expected result:
----------------
WHAT I EXPECT TO GET:
$line= <option value="1" selected>Option
1</option>
$chars_before=50
$front= <option value="1"
$back=>Option 1</option>
Actual result:
--------------
Just extracted: $NcharB4=49
Integer val: $chars_before=49
After some math: $chars_before=49
<option value="1"
$line= <option value="1" selected>Option
1</option>
$chars_before=49
Warning: chunk_split(): Chunk length should be greater than zero in
C:\XAMPP\htdocs\Cell_Modems\PHP\parse_form.php on line 1139
$front=
$back= <option value="1" selected>Option
1</option>
--
Edit bug report at https://bugs.php.net/bug.php?id=71634&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71634&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71634&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71634&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71634&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71634&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71634&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71634&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71634&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71634&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71634&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71634&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71634&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71634&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71634&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71634&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71634&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71634&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71634&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71634&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71634&r=mysqlcfg