php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #71634 String functions can't work with (purported) integer extracted from string
Submitted: 2016-02-19 19:46 UTC Modified: 2016-02-19 23:29 UTC
From: 4OtherBusiness at comcast dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.6.18 OS: Windows 7 Enterprise w/ SP 1
Private report: No CVE-ID: None
 [2016-02-19 19:46 UTC] 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>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-02-19 23:29 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2016-02-19 23:29 UTC] requinix@php.net
> if (!is_null($chars_before) && !$chars_before=0)
Count your equals signs.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 22:00:02 2026 UTC