K
K
konchober2015-12-05 23:31:49
PHP
konchober, 2015-12-05 23:31:49

How to do preg_replace for a tag containing an entry in PHP?

Hey!
There is an HTML page containing many tags.

<tag>lolo
ololo
lolo</tag>
<tag>ko
koko
ko</tag>
<tag>zaza
azaza
zaza</tag>
<tag>bom
terebon
bombom</tag>

You need to select only the tag that contains the occurrence of the word azaza:
<tag>zaza
azaza
zaza</tag>

The content of each tag can contain any number of lines.
Problem: jagular #<tag>.*?azaza.*?<\/tag>#shighlights text from the very first tag to the one containing the desired string:
<tag>lolo
ololo
lolo</tag>
<tag>ko
koko
ko</tag>
<tag>zaza
azaza
zaza</tag>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stalker_RED, 2015-12-05
@konchober

https://regex101.com/r/xL0pG2/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question