When people add comments to my site there is always a slash before apostrophies. Is there a line of code that will prevent this from happening?

Dani AI

Generated

— the backslashes are escape slashes added before quotes. and pointed out the immediate remedy of removing those slashes at display time; that works for symptom relief but does not address why they appear in the first place.

Most common causes: the old PHP feature "magic quotes" automatically escaped incoming GET/POST/COOKIE data, or your code (or a library) called an escaping function before saving. Check whether the slashes are stored in the database or only visible on the page. Inspect the raw row (via phpMyAdmin or a SELECT) — if the DB contains the slashes, fix the insertion code; if the DB is clean but the page shows slashes, remove the extra escaping step before output.

If the server is running an older PHP with magic quotes enabled, disable it in php.ini (magic_quotes_gpc = Off) or ask the host to disable it. On some setups running mod_php you can use an .htaccess directive; otherwise update the application to stop relying on magic quotes. The PHP manual documents the behavior and removal of magic quotes here: .

Long-term best practice: stop adding/removing slashes as a general strategy. Use parameterized queries (PDO or mysqli) for database work and escape only for output with htmlspecialchars when rendering HTML. That prevents double-escaping and avoids stored backslashes while keeping input handling secure. See the PDO prepared-statement documentation and htmlspecialchars docs for guidance: PDO prepared statements and htmlspecialchars.

Quick troubleshooting checklist: check phpinfo()/PHP version, search the codebase for addslashes/magic-quotes usage, inspect DB rows, and migrate to prepared statements.

Recommended Answers

All 2 Replies

stripslashes($var)

where $var is the variable with the escape slashes added.

You can use stripslashes function.

string stripslashes ( string cad)
For example:
\' is changed with '
\\' is changed with \'

ch.-

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.