Jump to content

Strip all charactors but A-Z, a-z and 0-9.... how?


jasonc

Recommended Posts

Been looking at php.net all morning and still can not work out how these string commands work.

how do i strip all but the A-Z and a-z and 0-9 charaters from a string?

thanks



example.

string = "a^bc de*fgAB$CDE@:FG1:2 34 5'[]~=-]*&^%"

becomes

string = "abc defgABCDEFG12 34 5"

and also allow for <returns> or newline or carridge returns of what ever there called when you hit enter.
For this you want to use the [a href=\"http://www.php.net/ereg_replace\" target=\"_blank\"]ereg_replace()[/a] function:
[code]<?php
$strip = "a^bc de*fgAB$CDE@:FG1:2 34 5'[]~=-]*&^%";
$strip = ereg_replace("[^[:space:]a-zA-Z0-9*_.-]", "",$strip);
echo $strip;
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.