在给定文本中查找PHP中特定文本的模式

时间:2020-03-25 13:50:43

标签: php regex preg-match-all

我很难找到具有preg_match_all模式的特定对象。我有条短信。很多数据。但是我只想找到一个特定的

就像我有一串文字

    sadasdasd:{"website":["https://bitcoin.org/"]tatic/cloud/img/coinmarketcap_grey_1.svg?_=60ffd80');display:inline-block;background-position:center;background-repeat:no-repeat;background-size:contain;width:239px;height:41px;} .cqVqre.cmc-logo--size-large{width:263px;height:45px;}
/* sc-component-id: sc-2wt0ni-0 */

但是我只需要找到"website":["https://bitcoin.org/"]。网站是动态数据的地方。例如网站可以是Google "website":["https://google.com/"]

现在我有这样的事情。那只是返回大量的URL。我只需要特定的

$pattern = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
preg_match_all($pattern, $parsePage, $matches);
print_r($matches[0]);

我的模式真的很糟糕,坚持了下来

1 个答案:

答案 0 :(得分:0)

像这样遍历数组:

    for ($x = 0; $x <= count(json_decode($array, true)) - 1; $x++) {
        if ($array[$x] == "your search criteria") {
            echo $array[$x];
            break;
        }
    }