【发布时间】:2012-09-16 00:36:54
【问题描述】:
所以我有这个脚本可以在更大的字符串中提取给定的字符串:
function get_string($string, $start, $end){
$string = " ".$string;
$pos = strpos($string,$start);
if ($pos == 0) return "";
$pos += strlen($start);
$len = strpos($string,$end,$pos) - $pos;
return substr($string,$pos,$len);
}
所以这是字符串:
$string= '<b>Sample Sample</b> <b>Sample2 Sample2</b>';
$output = get_string($string, '<b>','</b>');
echo $output;
我真的需要一些帮助,因为我没有想法。现在当我回显$output 我得到了
Sample Sample
我想做一个显示两者的更改:
Sample Sample
Sample2 Sample2
你们有没有任何想法如何修改函数并使其输出排序
一组结果$output[0], $output[1]?
提前谢谢你, 祝你有个美好的一天。
【问题讨论】:
-
我建议看
preg_match_all()php.net/manual/en/function.preg-match-all.php
标签: php string substring extract