Heim  >  Artikel  >  Backend-Entwicklung  >  请教下如何使用正则提取出<p>标签中的数字

请教下如何使用正则提取出<p>标签中的数字

WBOY
WBOYOriginal
2016-08-18 09:16:061003Durchsuche

网站代码如下 ,请教习如何在file_get_contentes 后通过正则匹配或者其他方法 获取出1500,0,0,0,这个四个数字,感谢 自己尝试了一下 无果,还望大神相助。请教下如何使用正则提取出<p>标签中的数字

以下是自己尝试 却没有成功

<code><?php header("Content-type:text/html;charset=utf-8");
$xmldata = file_get_contents("http://119977.vhost155.cloudvhost.net/data.php")
$preg = '#<p>.[0-9][人]{0,}.#isU';
preg_match_all($preg,$xmldata,$new_arr);
print_r($new_arr);
?></code>

回复内容:

网站代码如下 ,请教习如何在file_get_contentes 后通过正则匹配或者其他方法 获取出1500,0,0,0,这个四个数字,感谢 自己尝试了一下 无果,还望大神相助。请教下如何使用正则提取出<p>标签中的数字

以下是自己尝试 却没有成功

<code><?php header("Content-type:text/html;charset=utf-8");
$xmldata = file_get_contents("http://119977.vhost155.cloudvhost.net/data.php")
$preg = '#<p>.[0-9][人]{0,}.#isU';
preg_match_all($preg,$xmldata,$new_arr);
print_r($new_arr);
?></code>

<code><?php $preg = '/<p>.*?(\d+).*?/';

$str = '<p>asdff23sdfas</p>';

preg_match($preg,$str,$result);

echo "<pre class="brush:php;toolbar:false">";
print_r($result);

:([0-9]+)[个|人]

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