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] Link to comment https://forums.phpfreaks.com/topic/33253-solved-tough-one-replace-with-amp/ 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] Link to comment https://forums.phpfreaks.com/topic/33253-solved-tough-one-replace-with-amp/#findComment-155319 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" Link to comment https://forums.phpfreaks.com/topic/33253-solved-tough-one-replace-with-amp/#findComment-155337 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] Link to comment https://forums.phpfreaks.com/topic/33253-solved-tough-one-replace-with-amp/#findComment-155496 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};)/" Link to comment https://forums.phpfreaks.com/topic/33253-solved-tough-one-replace-with-amp/#findComment-529632 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.