Forum Moderators: coopster
I've done something similar before, but this is the first time I've ever needed to find something that also had content between the tags. What I'd like to do is have the search/replace ignore searching for the content between STRONG tags, and only add the class to the opening one.
So, here's is a working example, replacing a closing UL tag:
function fix_unordered_end ($content) {
$ul_end = "</ul>";
$rep_end = "</ul>" . "\n" . "<div class=\"innerbottom\"></div>" . "\n" . "<div class=\"bottom\"></div>" . "\n" . "</div>";
$content = str_replace($ul_end, $rep_end, $content);
return ($content);
}
add_filter('the_content', 'fix_unordered_end');
Like I said, this works like a charm. But what I *can't* get to work is that stuff between my STRONG tags. Right now, I'm at this point:
function fix_unordered_title ($content) {
$any = "(.+)";
$find = "<strong>$any</strong></p>" . "\n" . "<ul>";
$replace = "<strong class=\"title\">$1 hey</strong></p>" . "\n" . "<ul>";
$content = str_replace($find, $replace, $content);
return ($content);
}
add_filter('the_content', 'fix_unordered_title');
I've tried MANY variations on this theme - I can find the tags just fine, but when I try to "set aside" the text between my tags, nothing happens. So I know the rest is right - but my "$any" is what's wrong. I've tried what you see, as well as "/(.+)", "/(\w+)" and all kinds of other stuff.
There could be *anything* between the STRONG tags - I just can't seem to get my wildcard right. Can anyone help me figure this out? It's driving me nuts.
function fix_unordered_title ($content) {
$any = "(.+)";
$find = "<strong>$any</strong></p>" . "\n" . "<ul>";
$replace = "<strong class=\"title\">$1 hey</strong></p>" . "\n" . "<ul>";
$content = str_replace($find, $replace, $content);
return ($content);
}
You may want to use something like -
$find = '%<strong>(.+)</strong></p>\n<ul>%is';