Hi everyone, I have a submit form on my website that display's to the user once is has been submitted,
The problem I have is the text is being displayed as
Chris & Amy\'s 30th

It should be displayed as Chris & Amy's 30th
What is the best way to have this displayed correctly please.

Thanks in advance,

Dani AI

Generated

This looks like a classic case of HTML entities being stored (or re-encoded) in the database combined with literal backslashes being added by an escaping routine. The example posted — Chris & Amy\'s 30th — shows both an HTML entity (&, ') and a backslash before the numeric entity, which usually means the text was encoded/escaped more than once (addslashes/magic_quotes or similar) or encoded before insertion and again on output.

Practical checks: inspect the raw value in the database (via phpMyAdmin or the mysql client) to see whether the stored row contains & / ' or actual ' characters, and whether backslashes (\) are present. Search the code paths that write to the DB for calls to htmlentities, htmlspecialchars, addslashes or manual escaping — and remove HTML-escaping at the insert step. Use prepared statements for DB safety and keep escaping for HTML strictly at render/output time.

For a short-term display fix and for one-time migration, decode entities and strip slashes before producing HTML, then re-escape for safe output. Example sequence (run on the retrieved text, or in a migration script; always back up first):

// get raw value from DB into $txt
$txt = html_entity_decode($txt, ENT_QUOTES | ENT_HTML5, 'UTF-8');
$txt = stripslashes($txt);
echo htmlspecialchars($txt, ENT_QUOTES, 'UTF-8');  // safe final output

Long-term solution: migrate stored rows to plain text (decode entities and remove artificial slashes), ensure the DB and connection use UTF-8/utf8mb4, stop double-encoding in the application, and always escape at output. and were on the right track about decoding and checking the PHP functions — the important part is to fix the encoding/escaping pipeline so the problem does not recur.

Recommended Answers

All 3 Replies

Share the PHP that has the "Chris & Army" text string in it so folk can see what's going on.

<?php
$var = "Chris & Amy's 30th";
echo htmlspecialchars_decode($var);
?>

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.