I've very odd task to do.
I need to grab text from html tags using preg_match() function in PHP. Problem is that text I need is between closing and opening html tags or this text with tags.
Below is my html string:
<h2>Title of post</h2> 1 category <strong>task 1</strong> 1 category <strong>task 2</strong> 1 category <strong>task 3</strong>
To be more specific: I need string " 1 category " between </h2>
and <strong>
tag.
When i try to grab text between opening and closing tags - It's working fine and I'm using this function:
preg_match_all('#<strong>(.*?)</strong>#',$string,$matches);
I've tried many combinations to get text between closing and opening tags. None of them worked out. I've ended using function like this:
preg_match_all('#<\/strong>(.*?)<strong>#',$content,$matches_all);
With no results.
The strange thins is that on online regex testers this function with above pattern with above function works sometimes.
Do I have bad pattern? Am I missing some flags? Do you know what can be best way to get text in this way? Unfortunately I have to do with Regex approach, the solutions like XMLDomParser is not allowed in my case.
Thanks a lot for help.