且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

从PHP中的字符串中删除单引号

更新时间:2023-02-23 09:38:00

使用当前的str_replace方法:

Using your current str_replace method:

$FileName = str_replace("'", "", $UserInput);

虽然很难看到,但第一个参数是双引号,然后是单引号和双引号.第二个参数是两个双引号,中间没有任何引号.

While it's hard to see, the first argument is a double quote followed by a single quote followed by a double quote. The second argument is two double quotes with nothing in between.

使用str_replace,您甚至可以拥有要完全删除的字符串数组:

With str_replace, you could even have an array of strings you want to remove entirely:

$remove[] = "'";
$remove[] = '"';
$remove[] = "-"; // just as another example

$FileName = str_replace( $remove, "", $UserInput );