Jump to content

Archived

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

jasonc

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

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.

Share this post


Link to post
Share on other sites
$strip = "a^bc de*fgAB$CDE@:FG1:2 34 5'[]~=-]*&^%";

$striped=stripslashes($strip);

echo $striped;


use str_replace put the unwanted words in an array then str_replace.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.