What are alternative functions in PHP that can be used for adding and removing slashes more securely?

When adding or removing slashes in PHP, it is important to do so securely to prevent vulnerabilities such as SQL injection attacks. Instead of using addslashes() and stripslashes(), which are not recommended due to potential security risks, you can use the functions mysqli_real_escape_string() and stripslashes() to add and remove slashes securely.

// Add slashes securely
$secure_data = mysqli_real_escape_string($connection, $input_data);

// Remove slashes securely
$clean_data = stripslashes($input_data);