michaellunsford Posted January 7, 2007 Share Posted January 7, 2007 I want to search through an array and replace every isolated occurance of "&" with "&" -- the catch is, I don't want to replace encoded characters, like & etc.I can build an expression that does the exact opposite -- but having trouble the other way around. Here's "the opposite":[code]<?php$blah=array('bob & brenda', 'bob & brenda', 'bob brenda ');do { echo preg_replace("*&[A-Za-z]{2,4};*"," ",current($blah))."\n";}while(next($blah));?>[/code] Quote Link to comment Share on other sites More sharing options...
effigy Posted January 7, 2007 Share Posted January 7, 2007 Assuming that all &'s should be followed by whitespace of some kind: [tt]/&(?=\s+)/[/tt] Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 7, 2007 Author Share Posted January 7, 2007 Sometimes it's not... Like "B&H Photo" Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted January 8, 2007 Author Share Posted January 8, 2007 HA got it ;D[code]"/&(?![A-Za-z]{2,5};)/"[/code] Quote Link to comment Share on other sites More sharing options...
michaellunsford Posted April 29, 2008 Author Share Posted April 29, 2008 revised: should now also correctly identify decimal and hexadecimal numeric character references: "/&(?![A-Za-z#0-9]{2,6};)/" 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.