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; }
var_dump($length)
, see what's in there.remove foreach loop , instead put line
$passed_string = str_replace($matches,"_",$passed_string);
add
" "
in $matches array , can rid of line$passed_string = str_replace(" ","_",$passed_string);
Comments
Post a Comment