Forum Moderators: coopster
What I need to do is change all instances (though there's only one) of the occurance
<td class="maincenter" vAlign="top"> ... </td> in my code to
<div id="maincenter"> ... </div> I wasn't sure whether to use JS or PHP; I've looked into string and preg replaces, but I can't seem to get either to work.
Feedback is greatly appreciated.
$s="Other stuff<td class=\"maincenter\" vAlign=\"top\">Contents of block</td>Other Stuff";
$s=preg_replace("#<td class=\"maincenter\" vAlign=\"top\">(.*[^</td>])</td>#","<div id=\"maincenter\">\\1</div>",$s);
echo $s;
This will work if you're sure that your formatting of the replace string is exactly as described - i.e. it won't check for optional spacing, case irregularity etc etc.
Output buffering sounds like it might be more of what I wanted to do; how would I go about solving my problem in that respect?
I've just spent about 4 or 5 straight hours tampering with my code, and I'm still as lost as ever. I'm trying to teach myself how to do it, but attempting to interpret the PHP Manual into plain English never ceases to give me a headache.
I would post my faulty code, but I doubt it would serve any good seeing as it's all just experimental. Basically, when I'm not getting an error, my output either just adds another block (rather than rewriting the original), or it leaves me with no markup whatsoever.
Suffice it to say, I'm very confused.