AndyPSV
asked on
How to build a function (PHP) which replaces....
everything about: 0-9, a-z, A-Z, _
replaces on '' (deletes)
replaces on '' (deletes)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To replace everything that ISN'T alphanumeric and/or "_" you can use this:
$new_string = preg_replace(/[^a-zA-Z0-9_\s]/, , $string);
Like in this example:
$new_string = preg_replace(/[^a-zA-Z0-9_\s]/, , $string);
Like in this example:
<?php
$string = Here! is some text, and numbers 12345, and symbols !£$%^&;
$new_string = preg_replace(/[^a-zA-Z0-9_\s]/, , $string);
echo $new_string; // It shows: Here is some text and numbers 12345 and symbols
?>
And to test it:
echo myDelete("123 abdx **&&++__");
You want a function that takes a string and deletes those characters?
Can you show a string to pass to the "function" and what the desired output would be ?