将特殊字符转换为数组的php字符串
我有一个名为将特殊字符转换为数组的php字符串,php,arrays,variables,Php,Arrays,Variables,我有一个名为$array的PHP变量,它将输出类似 “…”、“…”、“…”、“…”、“…”、“…”当回音时 但是…可能包含一些字符,如“,,和空格,甚至可能包含”,“ 如何将其更改为类似数组的数组([0]=>…[1]=>…[2]=>…[3]=>…等)?
$array
的PHP变量,它将输出类似“…”、“…”、“…”、“…”、“…”、“…”
当回音时
但是…
可能包含一些字符,如“,,
和空格,甚至可能包含”,“
如何将其更改为类似数组的数组([0]=>…[1]=>…[2]=>…[3]=>…等)
?
您可以使用str_replace函数:
$str = "....'...,,,";
$unwantedChars = array("'", ",");
$cleanString = str_replace($unwantedChars, "",$str);
echo $cleanString;
您可以在unwantedChar数组中添加任意数量的字符尝试,也可以使用基本的str\u replace函数,这样基本上您就有了一个CSV?可以…包含,“
?…可以包含任何内容
$str = "....'...,,,";
$unwantedChars = array("'", ",");
$cleanString = str_replace($unwantedChars, "",$str);
echo $cleanString;