Removing special Characters from string
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