jasonc Posted June 2, 2006 Share Posted June 2, 2006 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?thanksexample.string = "a^bc de*fgAB$CDE@:FG1:2 34 5'[]~=-]*&^%"becomesstring = "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 https://forums.phpfreaks.com/topic/11012-strip-all-charactors-but-a-z-a-z-and-0-9-how/ Share on other sites More sharing options...
redarrow Posted June 2, 2006 Share Posted June 2, 2006 $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. Link to comment https://forums.phpfreaks.com/topic/11012-strip-all-charactors-but-a-z-a-z-and-0-9-how/#findComment-41129 Share on other sites More sharing options...
kenrbnsn Posted June 2, 2006 Share Posted June 2, 2006 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 https://forums.phpfreaks.com/topic/11012-strip-all-charactors-but-a-z-a-z-and-0-9-how/#findComment-41156 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.