What are some potential pitfalls to be aware of when manipulating strings in PHP?

One potential pitfall when manipulating strings in PHP is not properly sanitizing user input, which can lead to security vulnerabilities such as SQL injection or cross-site scripting attacks. To mitigate this risk, always validate and sanitize user input before using it in string manipulation functions.

// Example of sanitizing user input using the filter_var function
$user_input = $_POST['user_input'];
$sanitized_input = filter_var($user_input, FILTER_SANITIZE_STRING);