Either decode them using html_entity_decode or remove them using preg_replace:
$Content = preg_replace("/&#?[a-z0-9]+;/i","",$Content);
(From here)
EDIT: Alternative according to Jacco's comment
might be nice to replace the '+' with {2,8} or something. This will limit the chance of replacing entire sentences when an unencoded '&' is present.
$Content = preg_replace("/&#?[a-z0-9]{2,8};/i","",$Content);
Use html_entity_decode to convert HTML entities.
You'll need to set charset to make it work correctly.
try to replace the regular expectation change
preg_replace('/[^A-Za-z0-9\-]/', '', $string);
with
preg_replace("/[^A-Za-z0-9\-\']/", '', $string); // escape apostraphe
or
you can str_replace It is quicker and easier than preg_replace() Because it does not use regular expressions.
$text = str_replace("'", '', $string);
In a more detailed manner from Above example, Considering below is your string:
$string = '<div>This..</div> <a>is<a/> <strong>hello</strong> <i>world</i> ! ูุฐุง ูู ู
ุฑุญุจุง ุงูุนุงูู
! !@#$%^&&**(*)<>?:";p[]"/.,\|`~1@#$%^&^&*(()908978867564564534423412313`1`` "Arabic Text ูุต ุนุฑุจู test 123 ู,.m,............ ~~~ ูุ]ูู}~ู]ู}"; ';
Code:
echo preg_replace('/[^A-Za-z0-9 !@#$%^&*().]/u','', strip_tags($string));
Allows: English letters (Capital and small), 0 to 9 and characters !@#$%^&*().
Removes: All html tags, and special characters other than above