What are the best practices for escaping characters in PHP strings when concatenating variables?

When concatenating variables in PHP strings, it is essential to escape characters properly to prevent injection attacks and ensure the correct interpretation of the concatenated values. To escape characters in PHP strings, you can use the `htmlspecialchars()` function to convert special characters to HTML entities or use the `addslashes()` function to add slashes before special characters like quotes.

// Example of escaping characters in PHP strings when concatenating variables
$name = "John";
$message = "Hello, " . htmlspecialchars($name) . "! How are you?";
echo $message;