Trim more than whitespace

Hi,

I have a search functionality on my website, and aswel as using trim to trim white space before and after the keyword, I would also like it to trim anything else out that isnt in the alphabet.

Here is what I am using:


  $var = @$_GET['q'] ;
  $trimmed = trim($var);

Can this be done?

Sure is, see [fphp]preg_replace/fphp. :slight_smile:

Hi OK cheers,

Got the jist of that.

Do you have anything handy that basically trims everything out other than a letter, and replaces it with nothing

preg_replace('~[^a-z]~i', null, $string);

:wink:

Thank you Anthony

Cheers


/**
	 * Strips extra whitespace from output
	 *
	 * @param string $str String to sanitize
	 * @return string whitespace sanitized string
	 * @access public
	 * @static
	 */
	public static function stripWhitespace($str) {
		$r = preg_replace('/[\
\\r\	]+/', '', $str);
		return preg_replace('/\\s{2,}/', ' ', $r);
	}


Above function is extracted from CI :slight_smile: Enjoy