I need to replace Microsoft Word's version of single and double quotations marks (“ ” ‘ ’
) with regular quotes (' and ") due to an encoding issue in my application. I do not need them to be HTML entities and I cannot change my database schema.
I have two options: to use either a regular expression or an associated array.
Is there a better way to do this?
A single-quoted string only uses the escape sequences for a single quote or a backslash. Here are some common escape sequences for double-quoted strings: \" for a double quote. \\ for a backslash.
Encoding quotation marks (") is in practice only needed if the're inside an attribute, however for the HTML code to be correct (passing HTML validation), you should always encode quotation marks as " . Apostrophes (') don't need escaping in HTML. In XHTML they should be encoded as ' .
I have found an answer to this question. You need just one line of code using iconv()
function in php:
// replace Microsoft Word version of single and double quotations marks (“ ” ‘ ’) with regular quotes (' and ") $output = iconv('UTF-8', 'ASCII//TRANSLIT', $input);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With