PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Does anyone know of a regexp that can be used with preg_replace that can replace all ampersands which are not connected to an HTML entity into an HTML entity.
What cases would it need to match? Wouldn't it just be any ampersand followed by whitespace, or by an alphanumeric string that doesn't have a semi-colon at the end? I can't think of anything else it'd need to match...
But..
Why can't you use html_entity_decode() followed by htmlentities()? Wouldn't that achieve the same result?
What cases would it need to match? Wouldn't it just be any ampersand followed by whitespace, or by an alphanumeric string that doesn't have a semi-colon at the end?
I can't think of any either. But, being regex-illiterate, I don't even know how to put that together. If you could do the honours and also add an explanation for each part of the pattern, that would be fantastic.
Why can't you use html_entity_decode() followed by htmlentities()? Wouldn't that achieve the same result?
Actually, running html_entity_decode() alone seems to have done the trick. I am in a bit confusion right now as to what's going on.