Pattern to find specific text in PHP in given text [duplicate]

血红的双手。 提交于 2020-05-09 17:20:45

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!