Getting ’ instead of an apostrophe(') in PHP

This can occur if your PHP code is using the ISO-8859-1 character set instead of UTF-8. To fix this issue, you can change the character set to UTF-8 in your PHP script by including the following line at the top of your script:

header('Content-Type: text/html; charset=UTF-8');

Watch a course Learn object oriented PHP

You can also change the character set in your HTML by including the following line within the <head> section of your HTML document:

<meta charset="UTF-8">

Additionally, you can also change the character set in your database if you are using one.

Here's a full example of how you can handle the issue of getting ’ instead of an apostrophe (') in PHP:

<?php
$text = "Here's an example of using an apostrophe in PHP";

// Convert the string to UTF-8 encoding
$text = mb_convert_encoding($text, 'UTF-8');

echo $text;
?>

This code uses the mb_convert_encoding() function to convert the string to UTF-8 encoding, which is a widely used and well-supported character encoding that can handle apostrophes and other special characters properly. By converting the string to UTF-8 encoding, you can ensure that the apostrophe is properly displayed in your output.