As the title says, I’m trying to use PHP to convert the character » into it’s html entity. This is not our final solution, but before some other major changes are finished, we need this as a quick fix.
I’m trying to test out with the following code, but its not working as I’d wanted.
<form action="test.php" method="post">
<input type="text" name="test" />
<input type="submit" value="Go" />
</form>
<?php
if (isset($_POST['test'])){
$converted = preg_replace('/\xbb/', '»', $_POST['test']);
echo '<div>Original: '.$_POST['test'].'</div>';
echo '<div>Converted: '. $converted.'</div>';
}
?>
The converted seems to be correct but we are getting an extra character before the » which shows in Firefox’s view source as just a ? in a square, but I’m not sure what it actually is or why it is there.
Please can someone help? Thank you.
»isc2 bbin UTF-8 butbbin ISO-8859-1.When outputting this on a page that is not UTF-8 encoded, you’ll see something like this:
The chances are, the character is being posted through as UTF-8. That means the second byte is being replaced, but the first remains, so you end up with
c2followed by»Try
or