I’ve constructed a form, but some rows of the form can potentially be returned blank, with default values. I’m trying to find a way of searching the form output and then deleting the bit which I know is not needed – which looks like:
<tr bgcolor="#FFFFFF">
<td>2E</td>
<td id="8003">-800</td>
</tr>
I’ve used str_replace() effectively on a couple of bits, but my major problem is that bgcolor=”#FFFFFF” can CHANGE to different hex values and also
I could write a str_replace() for every possible outcome I guess, but is there a preg_replace solution for anything like this? It would have to be a pretty complicated regular expression.
A regex to match hexadecimal strings is actually quite easy:
You’ll probably hear that you should use a HTML parser to remove the unwanted nodes – maybe you should, but if you know what the input string is going to be like, then maybe not.
To match that first line in your example, you’d need this regex: