bcamp1973 Posted August 23, 2006 Share Posted August 23, 2006 ok, i want to strip all instances of "\r\n", "\r", "\n","\t" and non-alpha numeric characters from a string. in my searching through the PHP manual there seems to be a lot of options...such as str_replace, preg_replace(), ereg_replace() etc. i need something that's fast an efficient and i'm guessing i'll have to use regex of some form but it's not something i'm very knowledgable of. any suggestions? Link to comment https://forums.phpfreaks.com/topic/18447-stripping-all-non-alpha-numeric-characters-from-string/ Share on other sites More sharing options...
Caesar Posted August 23, 2006 Share Posted August 23, 2006 Take the reverse approach, only match those characters you want to retrieve. ;-) Link to comment https://forums.phpfreaks.com/topic/18447-stripping-all-non-alpha-numeric-characters-from-string/#findComment-79408 Share on other sites More sharing options...
obsidian Posted August 23, 2006 Share Posted August 23, 2006 i like this approach:[code]<?php$String = preg_replace('|[^a-z0-9]|i', '', $String);echo $String;?>[/code] Link to comment https://forums.phpfreaks.com/topic/18447-stripping-all-non-alpha-numeric-characters-from-string/#findComment-79464 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.