以下两种方法都能达到效果
但用正则可能对资源有些浪费
[php]
<?php
$str='/ewebeditor/uploadfile/20081222093646223.jpg|../ewebeditor/uploadfile/20081222093649254.gif|ewebeditor/uploadfile/20081222093649254.gif';
$arr = explode('|', $str);
print_r($arr);
preg_match_all('/.+?(?=\||$)/', $str, $arr2);
print_r($arr2);
?>
[/php]
但用正则可能对资源有些浪费
[php]
<?php
$str='/ewebeditor/uploadfile/20081222093646223.jpg|../ewebeditor/uploadfile/20081222093649254.gif|ewebeditor/uploadfile/20081222093649254.gif';
$arr = explode('|', $str);
print_r($arr);
preg_match_all('/.+?(?=\||$)/', $str, $arr2);
print_r($arr2);
?>
[/php]
preg_match('/.+?(?=\||$)/',$allimages,$matches);使用上面的语句OK了,这个“\||$”应该是查找以“|”结束的地方,为什么要两个“|”?
另外不在有随机要求,现在是可否让取出的值不包括“|”符号呢?
| 或 结束
不像出现可以如下:<?php
$str='/ewebeditor/uploadfile/20081222093646223.jpg|../ewebeditor/uploadfile/20081222093649254.gif|ewebeditor/uploadfile/20081222093649254.gif';
//$arr = explode('|', $str);
//print_r($arr);preg_match_all('/(.+?)(?:\||$)/', $str, $arr2);
print_r($arr2[1]);
?>