Monday, October 24, 2011

PHP, text after apostrophe or hyphen cutoff



In some scenarios when a piece of text is pasted from Word to online visual editor, if the text contains an apostrophe or hyphen, all text that comes after the apostrophe or hyphen will not cutoff in MYSQL database. mb_convert_encoding function can be used to solve this problem:

$sql_subject =mb_convert_encoding($_POST['subject'], 'HTML-ENTITIES', 'OLD-ENCODING');
$sql_subject =ereg_replace("’", "'", $sql_subject);
$sql_subject=$addslashes(html_entity_decode($sql_subject));

’ is for  ',  mb_convert_encoding will automatically solve hyphen cutoff problem.

For using function mb_convert_encoding:
In C:/php5.3.1/php.ini, line 960, un-comment
extension=php_mbstring.dll

No comments:

Post a Comment