php - Error using substr() -


i getting error while using substr:

warning: substr() expects parameter 3 long

i new php , not locate problem. appreciate help.

here code:

function prepare_string($passed_string,$length)     {         $matches = array("`","!","@","®","©","~","#","$","%","^","&","*","-","=","+","|","\\","[","{","]","}","(",")",";",":","\"","'",",","<",">",".","?","/","\'","\\","'","’");         $passed_string =substr($passed_string,0,$length);         for($i=0;$i<count($matches);$i++)         {             $passed_string = str_replace($matches[$i],"_",$passed_string);         }         $passed_string = str_replace(" ","_",$passed_string);         return $passed_string;     } 

  1. var_dump($length) , see what's in there.

  2. remove foreach loop , instead put line $passed_string = str_replace($matches,"_",$passed_string);

  3. add " " in $matches array , can rid of line $passed_string = str_replace(" ","_",$passed_string);


Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -