How to Find Next String After the Needle Using Strpos()

前端 未结 3 1652
情话喂你
情话喂你 2021-01-20 09:35

I\'m using PHP strpos() to find a needle in a paragraph of text. I\'m struggling with how to find the next word after the needle is found.

For

3条回答
  •  [愿得一人]
    2021-01-20 10:27

    You could do this with a single regular expression:

    if (preg_match_all('/(SCREENSHOT|LINK) (\S+?)/', $description, $matches)) {
        $needles = $matches[1]; // The words SCREENSHOT and LINK, if you need them
        $links = $matches[2]; // Contains the screenshot and/or link URLs
    }
    

提交回复
热议问题