poe Posted October 19, 2007 Share Posted October 19, 2007 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 Quote Link to comment Share on other sites More sharing options...
effigy Posted October 19, 2007 Share Posted October 19, 2007 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> Quote Link to comment Share on other sites More sharing options...
poe Posted October 19, 2007 Author Share Posted October 19, 2007 it could be for >numbers/numbers< OR >letters/letters< OR >letters or numbers / letters or numbers< Quote Link to comment Share on other sites More sharing options...
effigy Posted October 19, 2007 Share Posted October 19, 2007 If by "letters" you mean ASCII, replace \d with [a-zA-Z0-9]. Quote Link to comment Share on other sites More sharing options...
poe Posted October 19, 2007 Author Share Posted October 19, 2007 awsome, thankyou! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.