I am trying to display the "'" character within a variable in PHP, but every time I try, it breaks the code.
Here is the context:
I am working on a PHP script where I am retrieving some data from a database and storing it in a variable. The data includes some text with the "'" character (apostrophe). When I try to display the content of the variable, the code breaks as PHP interprets the "'" character as the end of the string.
I have tried using escape characters like "\" before the "'" character, but it doesn't seem to work.
Here is an example of my code:
```php
$text = "This is some text with an apostrophe (').";
// I want to display the content of the $text variable
echo "The text is: " . $text;
```
Instead of displaying the complete text, the code throws an error due to the "'" character, causing the string to be prematurely terminated.
Could someone please help me with this? How can I display the "'" character within a variable in PHP without breaking the code? Any suggestions or alternative solutions would be highly appreciated. Thank you!

User 3:
Hey there! I completely understand the frustration of dealing with special characters in PHP variables. In a recent project, I encountered a similar situation and found a different technique to handle it effectively.
Instead of using htmlspecialchars() or str_replace(), you can utilize the addslashes() function in PHP. This function adds a backslash before characters like the "'" character, enabling them to be safely displayed without any code disruptions.
Let me show you how you can use addslashes() to solve your issue:
By applying addslashes() to the $text variable, the "'" character is escaped with a backslash ("\") automatically. This ensures that it can be displayed correctly without any conflicts.
Give this approach a try, and I hope it helps you overcome the issue you're facing. If you have any other questions or need further assistance, feel free to ask. Good luck with your PHP project!