Bug #71634 [Opn->Nab]: String functions can't work with (purported) integer extracted from string
| From: | requinix@php.net | Date: | Fri, 19 Feb 2016 23:29:43 +0000 |
| Subject: | Bug #71634 [Opn->Nab]: String functions can't work with (purported) integer extracted from string | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-199352@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=71634&edit=1
ID: 71634
Updated by: requinix@php.net
Reported by: 4OtherBusiness at comcast dot net
Summary: String functions can't work with (purported) integer
extracted from string
-Status: Open
+Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Windows 7 Enterprise w/ SP 1
PHP Version: 5.6.18
Block user comment: N
Private report: N
New Comment:
> if (!is_null($chars_before) && !$chars_before=0)
Count your equals signs.
Previous Comments:
------------------------------------------------------------------------
[2016-02-19 19:46:12] 4OtherBusiness at comcast dot net
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 this bug report at https://bugs.php.net/bug.php?id=71634&edit=1