问题
I have trouble to find specific object with preg_match_all
pattern. I have a text. A lot datas. But I would like to find just one specific
Like I have a string of text
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 */
However I just need to find "website":["https://bitcoin.org/"]
. Where website is dynamic data. Such as website can be a google "website":["https://google.com/"]
Right now I have something like this. That's just return a bulk of urls. I need just specific
$pattern = '#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#';
preg_match_all($pattern, $parsePage, $matches);
print_r($matches[0]);
I am really bad in patterns and stuck on that
回答1:
Loop through the array like this:
for ($x = 0; $x <= count(json_decode($array, true)) - 1; $x++) {
if ($array[$x] == "your search criteria") {
echo $array[$x];
break;
}
}
来源:https://stackoverflow.com/questions/60850247/pattern-to-find-specific-text-in-php-in-given-text