日期:2014-05-17  浏览次数:20387 次

PHP如何在给定字符串中查找出特定两个字符之间的内容?
<div class="well"><p>查询的 IP:<code>219.245.125.100</code> 来自:陕西省西安市 西安电子科技大学</p><p>GeoIP: Xidian, China</p><p></p><p>您今日已查询 14 次,最多可查 100 次。</p></div>

如上,想获取“来自:”和"</p><p>GeoIP:"之间的“陕西省西安市 西安电子科技大学”,该如何处理?

------解决方案--------------------
PHP code
$s=<<<div
<div class="well"><p>查询的 IP:<code>219.245.125.100</code> 来自:陕西省西安市 西安电子科技大学</p><p>GeoIP: Xidian, China</p><p></p><p>您今日已查询 14 次,最多可查 100 次。</p></div>
div;
preg_match('/来自:(.*?)<\/p><p>/',$s,$m);
echo $m[1];

------解决方案--------------------
将给定字符串保存在$current0中

$current='<<<div'.$current0.'div';
preg_match('/来自:(.*?)<\/p><p>/',$current,$result);
echo $result[1];