Heim  >  Artikel  >  Backend-Entwicklung  >  回来字符串截取循环

回来字符串截取循环

WBOY
WBOYOriginal
2016-06-13 11:49:09833Durchsuche

返回字符串截取循环
$return 返回值为
 9||50
||1|#|2013-09-09 00:00:22||13814002394||内容
||1|#|2013-09-09 00:00:19||13814002394||内容
||1|#|2013-09-07 00:51:57||15920531400||内容
||1|#|2013-09-06 22:21:02||15920531400||内容
||1|#|2013-09-06 22:13:14||15920531400||内容
||1|#|2013-09-06 22:07:42||15920531400||内容
||1|#|2013-09-05 14:00:02||15920531400||内容
||1|#|2013-09-05 12:10:13||15920531400||内容
||1|#|2013-09-05 12:01:27||15920531400||内容
||1|#|

//这是整理过的

是有规则的字符串(不是数组)
我变成可循环的数组 其中时间,号码,内容是变量!!!!!


------解决方案--------------------

<?php<br />	$str='9<br><font color='#FF8000'>------解决方案--------------------</font><br>50<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-09 00:00:22<br><font color='#FF8000'>------解决方案--------------------</font><br>13814002394<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-09 00:00:19<br><font color='#FF8000'>------解决方案--------------------</font><br>13814002394<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-07 00:51:57<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-06 22:21:02<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-06 22:13:14<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-06 22:07:42<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-05 14:00:02<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-05 12:10:13<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>2013-09-05 12:01:27<br><font color='#FF8000'>------解决方案--------------------</font><br>15920531400<br><font color='#FF8000'>------解决方案--------------------</font><br>内容<br />	<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>';<br />	$new_str=str_replace('<br><font color='#FF8000'>------解决方案--------------------</font><br>','<br><font color='#FF8000'>------解决方案--------------------</font><br>',$str);<br />	$arr=explode('<br><font color='#FF8000'>------解决方案--------------------</font><br>1<br><font color='#FF8000'>------解决方案--------------------</font><br>#<br><font color='#FF8000'>------解决方案--------------------</font><br>',$new_str);<br />	$new_arr=array();<br />	foreach ($arr as $value) <br />	{<br />		echo $value;<br />		if (substr_count($value,'<br><font color='#FF8000'>------解决方案--------------------</font><br>')>1) <br />		{<br />			$new_arr[]=explode('<br><font color='#FF8000'>------解决方案--------------------</font><br>',$value);<br />		}<br />	}<br />	echo "<pre class="brush:php;toolbar:false">";<br />	print_R($new_arr);<br />	echo "
";
?>
简单的写了下,凑合着能,不知道有没有什么更好的办法

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn