php - preg_replace td in table -
i have in mysql stored html table.
i need modify values of td.
for example:
<tr>...<td class="(different classes)" name="mynamea">20</td>...</tr> <tr>...<td class="(different classes)" name="mynameb">10</td>...</tr>
i need:
<tr>...<td class="(different classes)" name="mynamea">(20 * 0,60)</td>...</tr> <tr>...<td class="(different classes)" name="mynameb">(10 * 0,60)</td>...</tr>
thanks lot.
here need :)
$re = '/(<tr>(?:.*?)<td (?:.*?) name="mynamea">)(.*?)(<\/td>(?:.*?)<\/tr>)/'; $str = '<tr>...<td class="(different classes)" name="mynamea">20</td>...</tr>\n<tr>...<td class="(different classes)" name="mynameb">10</td>...</tr>'; preg_replace_callback( $re, function ($matches) { echo htmlspecialchars(strtolower($matches[1]).'('.strtolower($matches[2]).' * 0,60)'.strtolower($matches[3])); }, $str );
output
<tr>...<td class="(different classes)" name="mynamea">(20 * 0,60)</td>...</tr>
for matching mynameb
change mynamea
mynameb
, display html instead of text remove htmlspecialchars()
function code
Comments
Post a Comment