Hi everyone,

I'm new to PHP and I am trying to get to grips with the PHP scripts that have been created for my website.

One of my pages is a list of destinations and one of the places is Cote d'Azur.

When it publishes the destination on the dynamic page it comes out as Cote d\'Azur.

Why does it does this and is there a solution to resolve this issue that I can make within the PHP file.

Many thanks

Dani AI

Generated

This is a classic case of the text being escaped somewhere before it reaches the page. As pointed out, PHP’s “magic quotes” or an explicit escaping call was most likely adding the backslash, explained why escaping functions are used, and confirmed the visual symptom was fixed by removing the escape on output. That fix works for display, but it’s worth checking why the slashes were added in the first place and then fixing the source.

How to diagnose: inspect the stored value directly (query the database or view the table in phpMyAdmin) to see whether the backslash is already in the data or is added when rendering. Use phpinfo() or check your php.ini if you’re on an older PHP release to see whether magic_quotes_gpc was enabled. Grep the codebase for addslashes, mysql_real_escape_string, or similar functions to find where escaping might be applied.

Longer-term fixes and safer workflows: stop relying on automatic or ad-hoc escaping. Disable magic quotes at the server level (for old PHP installs), clean incoming data once, then use parameterized queries (PDO or mysqli prepared statements) for database operations and htmlspecialchars when producing HTML output. Example pattern for safe insertion with PDO:

$stmt = $pdo->prepare('INSERT INTO destinations (name) VALUES (:name)');
$stmt->execute([':name' => $name]);

Cleaning existing data: back up the database first. Either export and run a controlled search-and-replace on the dump file or write a small script that reads rows, removes unwanted escaping, and updates only the tested rows. Verify on samples before running a global update — some backslashes may be legitimate. After cleanup, remove the root cause (magic quotes or redundant addslashes) so the issue does not reappear.

Recommended Answers

All 3 Replies

I have encountered this before and you might wanna research on "Magic Quotes" in the php manual. I don't know exactly what to tell you to do, but if you could give an example of your code that outputs the string it would be much better.

Member Avatar for Member #117553

Hi everyone,

I'm new to PHP and I am trying to get to grips with the PHP scripts that have been created for my website.

One of my pages is a list of destinations and one of the places is Cote d'Azur.

When it publishes the destination on the dynamic page it comes out as Cote d\'Azur.

Why does it does this and is there a solution to resolve this issue that I can make within the PHP file.

Many thanks

Read carefully the PHP manual. Special characters like quotes and slashes are reserved characters in PHP. If you want to have a special char inside a text, stored in a variable, you should add a slash before the special character. Thus PHP understands that this is a special char.

E.G.

you want to store this - Cote d'Azur in a variable. You have 2 ways to do that :
1. add a slash manually when loading the string into the variable
or
2. use the function addslashes('your string here');

in both cases, when you retrieve your variable, you will have a slash in front of the '

If you want to get rid of it, you should use stripslashes('string where there is a slash before apostrophe goes here');

For more information read here:

http://bg2.php.net/manual/en/function.stripslashes.php

Good Luck

Thank you everyone who has helped me!!

I've sorted this problem and used

<? echo stripslashes($field);?>
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.