php将特殊字符'&'转换为单个字符

I have a string containing character &

And i have got the same string from $_POST containing &. when i var_dump it, the string form post shows 4 more characters then the var_dump(_same_string_).

I want to treat special characters from "post" as a "single character". What should I do?

I tried:

$postString = (string)$postString;

tried:

vardump(htmlspecialchars($postString));

it shows & as &amp while in var_dump(_same_string_) & remains same.

To convert from html entities back to the characters. Like from &amp to &, and &gt to >. Use htmlspecialchars_decode().

To do it the other way around, like & to &amp, use htmlspecialchars().

You'll need to use htmlspecialchars_decode() in order to decode the html entity &

echo htmlspecialchars_decode("&"):
//&  

Live Demo


htmlspecialchars_decode()

Convert special HTML entities back to characters. This function is the opposite of htmlspecialchars(). It converts special HTML entities back to characters. The converted entities are: &, " (when ENT_NOQUOTES is not set), ' (when ENT_QUOTES is set), < and >.