Q:

Write a PHP script to remove all characters from a string except a-z A-Z 0-9 or " "

0

Write a PHP script to remove all characters from a string except a-z A-Z 0-9 or " ".

Sample string: abcde$ddfd @abcd )der]

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

<?php
$string = 'abcde$ddfd @abcd )der]';
echo 'Old string : '.$string.'';
$newstr = preg_replace("/[^A-Za-z0-9 ]/", '', $string);
echo 'New string : '.$newstr."\n";
?>

Sample Output:

Old string : abcde$ddfd @abcd )der]                         
New string : abcdeddfd abcd der

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now