Hi, I need to remove incorrect characters from a string. So lets say the string is 'T^^he Gold$£en R0"!ad' and i want to echo out 'The Golden Road' i have experimented with the trim function but could only remove the first bad character. Any ideas? thanks
<?php $domain = "T^^he Gold$£en R0\"!ad"; $toberemoved = array("^","/",":","$","*","&","@","%","(","{","£","!"); // add any char to be removed ... $domain = str_replace ($toberemoved,"" ,$domain); ?> PHP:
The posted method almost works but not quite, is there a while loop method i could use to remove characters between certain ascii value range?
What do you mean by almost but not quite? Rather than throw out characters within a "bad set", consider keeping only the characters within a "good set".
function alpha( $string ) { return preg_replace( '([^a-zA-Z ]+)', '', $string ); } echo alpha( 'T^^he Gold$£en Ro!ad' ) PHP:
Consider inserting 0-9 as well if you want to retain numbers too. Note the space after Z. It's important if you want to keep the spaces.