Jump to content

[SOLVED] replace all / except in a tag </>


poe

Recommended Posts

i have a string

<table><tr><td>8</td><td>date</td><td>10/15</td><td>W/L</td><td>2/11</td></tr></table>

 

how do i replace all instances of the '/' (slash) with a ':' (colon) except for when it is not in a tag like </td> or </table> etc...

 

i have, but does not work:

$strHtml = eregi_replace("(-|/)",":",$strHtml);

 

*** i also want to replace the dash with a colon, but that is not giving me a problem :)

Link to comment
https://forums.phpfreaks.com/topic/73961-solved-replace-all-except-in-a-tag/
Share on other sites

If it's always for the >digits/digits< format:

 

<pre>
<?php
$str = '<table><tr><td>8</td><td>date</td><td>10/15</td><td>W/L</td><td>2/11</td></tr></table>';
echo htmlspecialchars(preg_replace('#(?<=>)(\d+)/(?=\d+<)#', '\1:', $str));
?>
</pre>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.