How can one prevent strings from breaking or truncating at certain characters, such as periods, when stored in PHP variables?

When storing strings in PHP variables that contain characters like periods, it's important to properly escape or encode the string to prevent it from breaking or truncating unexpectedly. One common method is to use the `htmlspecialchars()` function to encode special characters like periods before storing the string in a variable. This will ensure that the string is stored and displayed correctly without any issues.

$string = "This is a string with a period (.) in it.";
$encoded_string = htmlspecialchars($string);
echo $encoded_string;