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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.