What are some common pitfalls when handling string manipulation in PHP, as seen in the given code snippet?
One common pitfall when handling string manipulation in PHP is not properly escaping special characters, which can lead to syntax errors or unexpected behavior. To solve this issue, it's important to use functions like `addslashes()` or `mysqli_real_escape_string()` to escape special characters before using the string in SQL queries or other contexts where they could cause issues.
// Incorrect code snippet
$name = $_POST['name'];
$query = "SELECT * FROM users WHERE name = '$name'";
// Corrected code snippet
$name = addslashes($_POST['name']);
$query = "SELECT * FROM users WHERE name = '$name'";