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

前端 未结 3 1655
情话喂你
情话喂你 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:25

    I did a little testing on my site using the following:

    $description = "Hello, this is a test paragraph. The SCREENSHOT mysite.com/screenshot.jpg and the LINK mysite.com/link.html is what I want to return.";
    
    $matches = array();
    preg_match('/(?<=SCREENSHOT\s)[^\s]*/', $description, $matches);
    var_dump($matches);
    echo '
    '; preg_match('/(?<=LINK\s)[^\s]*/', $description, $matches); var_dump($matches);

    I'm using positive lookbehind to get what you want.

提交回复
热议问题