0

In PHP, I'm trying to match the first paragraph tag that is not immediately followed by an <img> tag, and add a class to that paragraph tag.

For example, it would add a class to:

<p>Text</p>

and

<p><strong>Strong text</strong></p>

but not:

<p><img src="" /></p>

Here's what I have so far which successfully adds a class to the first paragraph tag, but it doesn't skip until it finds a paragraph tag that doesn't immediately contain an image:

preg_replace('/<p>/','<p class="first">', $text, 1);

Thoughts? Apologies if that doesn't make sense.

4

1 に答える 1

2
/<p>(?!<img)/<p class="first">/
于 2009-12-11T16:59:29.527 に答える