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

Pattern to find specific object in PHP in given text

我无法找到具有 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/"]

现在我有这样的东西。那只是 return 一大堆网址。我只需要具体的

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

我的模式真的很糟糕并且一直坚持

您可以获得网站前缀之后的所有数据,直到下一个 " 到来 [^"]+:

$parsePage = <<<PAGE
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 */';
PAGE;

$pattern = '#"website":\["(https?://[^"]+)#';
preg_match($pattern, $parsePage, $matches);
print_r($matches[1]);

matches[1]是取第一个匹配(匹配括号内的内容)

这会打印:

https://bitcoin.org/

你可以查看 here