tags:

views:

8

answers:

2

Hello,

I have a bunch of tables of data and I need to add a php function to them. The following is what the data normally looks like

<TR class="tr7">
 <TD class="td70"><FONT class="ft5">Chateauguay</FONT></TD>
 <TD class="td71">&nbsp;</TD>
 <TD class="td72">80</TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74">180</TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td75">290</TD>
 <TD class="td76">&nbsp;</TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td72">145</TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74">190</TD>
</TR>

And the following is what I need to have added.

<TR class="tr11">
 <TD class="td70"><FONT class="ft5">Boucherville</FONT></TD>
 <TD class="td71">&nbsp;</TD>
 <TD class="td72"><?=t(80)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74"><?=t(180)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td75"><?=t(290)?></TD>
 <TD class="td76">&nbsp;</TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td72"><?=t(145)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74"><?=t(190)?></TD>
</TR>

Notice the ###'s which are prices get the added to them where the ###'s are in the middle.

I want to do this via PHP, I'm thinking a preg exp, but I don't even know where to start. Obv, the write and read part is a fopen and fwrite/fread, etc.

  • Steve
A: 

Try this preg replace on each of your files.

return preg_replace("/\>([0-9]+)\</", "><?=t(\$1)?><", $text);
Mike C
A: 

This regex should do it for you:

echo preg_replace('~>([0-9]+)<~', '><?=t($1)?><', $html);

Will yield:

<TR class="tr7">
 <TD class="td70"><FONT class="ft5">Chateauguay</FONT></TD>
 <TD class="td71">&nbsp;</TD>
 <TD class="td72"><?=t(80)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74"><?=t(180)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td75"><?=t(290)?></TD>
 <TD class="td76">&nbsp;</TD>

 <TD class="td73">&nbsp;</TD>
 <TD class="td72"><?=t(145)?></TD>
 <TD class="td73">&nbsp;</TD>
 <TD class="td74"><?=t(190)?></TD>
</TR>
alexn