Home  >  Article  >  Backend Development  >  Please tell me how to use regular expressions to extract the numbers in the

tag.

Please tell me how to use regular expressions to extract the numbers in the

tag.

WBOY
WBOYOriginal
2016-08-18 09:16:061049browse

The website code is as follows. Please teach me how to get the four numbers 1500,0,0,0 through regular matching or other methods after file_get_contentes. Thanks for trying it myself but to no avail. I hope God can help me. Please tell me how to use regular expressions to extract the numbers in the <p> tag.

The following is what I tried without success

<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,}.</p>#isU';
preg_match_all($preg,$xmldata,$new_arr);
print_r($new_arr);
?></code>

Reply content:

The website code is as follows. Please teach me how to get the four numbers 1500,0,0,0 through regular matching or other methods after file_get_contentes. Thanks for trying it myself but to no avail. I hope God can help me. Please tell me how to use regular expressions to extract the numbers in the <p> tag.

The following is what I tried without success

<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,}.</p>#isU';
preg_match_all($preg,$xmldata,$new_arr);
print_r($new_arr);
?></code>

<code><?php

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

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

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

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

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

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:"e in phpNext article:"e in php