带有特殊字符到数组的php字符串

时间:2017-10-27 15:57:33

标签: php arrays variables

我有一个名为$array的PHP变量,它会输出类似的字母 "...", "...", "...", "...", ...时的echo...可能会包含某些字符,例如",和空格,甚至可能包含", " 如何将其更改为数组([0] => ... [1] => ... [2] => ... [3] => ... etc)

之类的数组

2 个答案:

答案 0 :(得分:0)

PHP explode

$array = explode(",",$array);  // split the string into an array([0] => '"..."', etc)

foreach ($array as $entry) {
    // clean up the strings as needed
}

答案 1 :(得分:-1)

您可以使用str_replace函数:

   $str = "....'...,,,";

   $unwantedChars = array("'", ",");

   $cleanString = str_replace($unwantedChars, "",$str);

   echo $cleanString;

您可以在您想要的unwantedChar数组中添加任意数量的字符