Home > Backend Development > PHP Tutorial > 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
Release: 2016-08-18 09:16:06
Original
1074 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

<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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template