1

I will be loading article titles into strings, and the authors of these titles may or may not use both single and double quotes. To use this imported text in a variable, how can I prevent this from breaking the code as I will not be able to escape the characters myself?

4 Answers 4

4

Escaping the quotes only matters if you're putting it into a string literal (or a database, of course). Simply having the string does not require them to be escaped.

1

You can safely use any quotes in your variables - there's no limit in this regard.

You should, however, consider escaping the characters depending on the context you are going to use these variables at. For example, if you wish to display some data on a terminal - no escaping is required, while if showing the very same data inside a web page you will have to take care of that.

For displaying characters in web context, you should use htmlentities().

For using the data to craft a URL, you will find urlencode() useful. http_build_query() might help as well.

0

You could use htmlentities().

See full documentation here

0

You can use predefined string function addslashes(). Please refer this link for more info http://php.net/addslashes

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.