0

我正在将图像的名称上传到数据库!

问题是名称在数据库中,名称前有一个空格!

问题出在哪里?

$original_name = strtolower(trim($arquivo['name']));
$caracteres = array("ç","~","^","]","[","{","}",";",":","´",",",">",
                   "<","-","/","|","@","$","%","ã","â","á","à","é",
                  "è","ó","§","ò","+","=","*","&","(",")","!","#","?",
                  "`","ã"," ","©","£");

$original_name = str_replace(' ', '', $original_name);
$final_name = str_replace($caracteres,"",$original_name);
4

1 回答 1

2

我建议使用允许字符的白名单,例如[a-zA-Z0-9_]

并使用:

$final_name = preg_replace("#[^a-z0-9_]+#i", "", $arquivo['name']);
于 2013-07-21T21:23:27.743 回答