Output text in between two words

前端 未结 1 756
一个人的身影
一个人的身影 2021-01-02 17:53

I would like to use PHP to input a certain text and the output should be the text in between two words. To clarify:

Input:

Lorem ipsum dolor sit amet         


        
相关标签:
1条回答
  • 2021-01-02 18:34
    $str = 'Lorem ipsum dolor sit amet';
    $word1 = 'ipsum';
    $word2 = 'amet';
    preg_match('/'.preg_quote($word1).'(.*?)'.preg_quote($word2).'/is', $str, $match);
    // result would be in $match[1]
    
    0 讨论(0)
提交回复
热议问题