I wrote a regular expression pattern that can detect if something is an html entity.
Code: Select all
$htmlEntityPattern = '/&ї#|\w]\w{1,6};/';Any of you regular expression guru's got an idea?
Thanks for your time.
EricS
Moderator: General Moderators
Code: Select all
$htmlEntityPattern = '/&ї#|\w]\w{1,6};/';Code: Select all
<?php
$text = preg_replace('/&(?!(?:#\d{1,4}|\w{1,6});)/', '&', $text);
?>Code: Select all
<?php
function htmlentities2($string) {
$translationTable = get_html_translation_table(HTML_ENTITIES, ENT_QUOTES);
$translationTable[chr(38)] = '&';
return preg_replace( "/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,4};|#x[0-9a-fA-F]{2,4};)/", "&", strtr($string, $translationTable));
}
?>