Php 使用了哪个分隔符?
我需要用不同的分隔符分隔字符串。因此,我找到并使用了以下代码:Php 使用了哪个分隔符?,php,split,explode,delimiter,Php,Split,Explode,Delimiter,我需要用不同的分隔符分隔字符串。因此,我找到并使用了以下代码: function explodeX($delimiters,$string) { $return_array = Array($string); $d_count = 0; while (isset($delimiters[$d_count])) { $new_return_array = Array(); foreach($return_array as $el_to
function explodeX($delimiters,$string)
{
$return_array = Array($string);
$d_count = 0;
while (isset($delimiters[$d_count]))
{
$new_return_array = Array();
foreach($return_array as $el_to_split)
{
$put_in_new_return_array = explode($delimiters[$d_count],$el_to_split);
foreach($put_in_new_return_array as $substr)
{
$new_return_array[] = $substr;
}
}
$return_array = $new_return_array;
$d_count++;
}
return $return_array;
}
它工作得很好,但现在,我需要反转它,找到它实际使用的delimeter。
我用了这样一句话:
$val=explodeX(array("+","-","*","/"), $input);
现在,我需要返回正确的分隔符
提前感谢。将使用您在
$delimiters
中设置的所有delimeters,如此行所示:
while (isset($delimiters[$d_count]))
$d_count
在循环的底部递增,$d_count++
,而$return_数组
在循环通过所有分隔符后返回,与指定的$string
分隔
要将正确的分隔符放回它以前所在的位置,您不能这样做,除非您修改在$return\u array
中返回的信息。这就是你要找的东西:
$return_array[] = $new_return_array;
$delim = $delimiters[$d_count];
$return_array['delim'] = new Array();
$return_array['delim'][$delim][] = $new_return_array;
$d_count++;
这将在返回结果的delim
索引下的子数组中存储由每个分隔符分隔的单词。那么你需要做的就是让它们重新内爆,就像这样:
$string2 = '';
foreach ( $return_array as $delim => $word )
{
// not sure how to reverse your function at this moment, will get back with this part...
}
请给出
$input
和预期输出的示例。