Search code examples
phphtmlregexsimple-html-dom

how to get all text of html file inside two specific keywords


I have a html file and two keywords and i want to get all text which resides inside those two keywords. Should i use regex? I want to take those two keywords as input. It would be helpful if you give an example.


Solution

  • Yes, use Regex: keyword1(.*?)keyword2. PHP example:

    preg_match_all('/'.$kwdOne.'(.*?)'.$kwdTwo.'/s', $str, $matches);
    

    Read: preg_match_all() and Pattern Modifiers.