Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在字符的最后一次出现时分解字符串_Php_Explode - Fatal编程技术网

Php 在字符的最后一次出现时分解字符串

Php 在字符的最后一次出现时分解字符串,php,explode,Php,Explode,我使用的是PHP7.4,我有以下字符串: Tester Test Street 11 (Nursing Home, Example), 1120 New York '-------------Split String here '-----------------------NOT HERE 当我执行explode()时,我得到

我使用的是
PHP7.4
,我有以下字符串:

Tester Test Street 11 (Nursing Home, Example), 1120 New York
                                             '-------------Split String here 
                                   '-----------------------NOT HERE   
当我执行
explode()
时,我得到:

$addressAll = explode(", ", "Tester Test Street 11 (Nursing Home, Example), 1120 New York");

/*
array(3) {
  [0]=>
  string "Tester Test Street 11 (Nursing Home"
  [1]=>
  string "Example)"
  [2]=>
  string "1120 New York"
}
*/
然而,我想得到:

array(3) {
  [0]=>
  string "Tester Test Street 11 (Nursing Home, Example)"
  [1]=>
  string "1120 New York"
}
关于如何仅拆分上次出现的
的任何建议

谢谢你的回复

用于查找输入字符串中最后一个逗号的位置,并提取位于最后一个逗号之前和之后的子字符串:

$input='Tester Test Street 11(养老院,示例),纽约1120';
$pos=strrpos($input,',');
$prefix=substr($input,0,$pos);
$suffix=substr($input,$pos+1);
查看。

用于查找输入字符串中最后一个逗号的位置,并提取位于最后一个逗号之前和之后的子字符串:

$input='Tester Test Street 11(养老院,示例),纽约1120';
$pos=strrpos($input,',');
$prefix=substr($input,0,$pos);
$suffix=substr($input,$pos+1);
查看它。

一个带有的解决方案。 字符串由一个逗号分隔,该逗号后面只跟不带逗号的字符,直到字符串的末尾

$input = 'Tester Test Street 11 (Nursing Home, Example), 1120 New York';

$array = preg_split('~,(?=[^,]+$)~',$input);
?=导致括号中的表达式不用作反向引用。

具有的解决方案。 字符串由一个逗号分隔,该逗号后面只跟不带逗号的字符,直到字符串的末尾

$input = 'Tester Test Street 11 (Nursing Home, Example), 1120 New York';

$array = preg_split('~,(?=[^,]+$)~',$input);

?=导致括号中的表达式不用作反向引用。

这是否回答了您的问题?如果
explode()。或者使用它并处理它返回的价值以实现你的目标,不要期望它做它不打算做的事情。这是否回答了你的问题?如果
explode()。或者使用它并处理它返回的值以实现您的目标,不要期望它做它不打算做的事情。