简体   繁体   English

来自HTML的php preg_match

[英]php preg_match from html

Hi I need to extract data from a web page, in this case I need to extract the number 278 from $sting. 嗨,我需要从网页中提取数据,在这种情况下,我需要从$ sting中提取数字278。

$string = 'title="Metal:| <table class="resourceTooltip">
            <tr>
                <th>Disponible:</th>
                <td><span class="">278&lt';

$regex ='~title="Metal:| <table class="resourceTooltip">
            <tr>
                <th>Disponible:</th>
                <td><span class="">\s*\((.*?)\)\s*&lt~';
    preg_match($regex , $postResult, $match);
    print_r($match);

Above code outputs: 上面的代码输出:

Array ( [0] => title="Metal: ) 

Ideally I'd like not to use url_decode function. 理想情况下,我不想使用url_decode函数。 Hope someone can point me in the right direction. 希望有人能指出正确的方向。

Try something much simpler: 尝试一些简单得多的方法:

$regex = "/Disponible:\D+(\d+)/";
preg_match($regex,$string,$match);
var_dump($match[1]);

The power of regexes come from their flexibility. 正则表达式的功能来自其灵活性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM