Jump to content


Photo

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


  • Please log in to reply
2 replies to this topic

#1 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 02 June 2006 - 09:19 AM

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.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 June 2006 - 11:17 AM

$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.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 02 June 2006 - 01:20 PM

For this you want to use the [a href=\"http://www.php.net/ereg_replace\" target=\"_blank\"]ereg_replace()[/a] function:
<?php
$strip = "a^bc de*fgAB$CDE@:FG1:2 34 5'[]~=-]*&^%";
$strip = ereg_replace("[^[:space:]a-zA-Z0-9*_.-]", "",$strip);
echo $strip;
?>

Ken




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users