acctman Posted April 27, 2009 Share Posted April 27, 2009 hi can someone help me with a sql query that will strip all non A-z and 0-1 characters from a field? I've already added the html escape string to all new sql inserts i just need to remove all the current. table: MemberInfo Field: m_aboutme Quote Link to comment https://forums.phpfreaks.com/topic/155854-sql-query-to-strip-all-non-a-z0-1-characters/ Share on other sites More sharing options...
KPH71 Posted April 27, 2009 Share Posted April 27, 2009 I would just use PHP for this - I don't know of a way to do this in mysql. You could use something like str_replace() in PHP. It would be useful to know what kind of data you are expecting... Quote Link to comment https://forums.phpfreaks.com/topic/155854-sql-query-to-strip-all-non-a-z0-1-characters/#findComment-820418 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 You could use something like str_replace() in PHP. preg_replace as he wants a specific, but unknown number of item(s), which I doubt str_replace would suffice for his need. Quote Link to comment https://forums.phpfreaks.com/topic/155854-sql-query-to-strip-all-non-a-z0-1-characters/#findComment-820545 Share on other sites More sharing options...
acctman Posted April 27, 2009 Author Share Posted April 27, 2009 You could use something like str_replace() in PHP. preg_replace as he wants a specific, but unknown number of item(s), which I doubt str_replace would suffice for his need. do you have an example of how this sql query would work? Quote Link to comment https://forums.phpfreaks.com/topic/155854-sql-query-to-strip-all-non-a-z0-1-characters/#findComment-820595 Share on other sites More sharing options...
premiso Posted April 27, 2009 Share Posted April 27, 2009 It would not be done in SQL, it would be done before the value is entered into SQL or upon retrieving the value from SQL. <?php $string = "stripallalpha%$%2324numerics"; $string = preg_replace("~([a-z0-9])~i", "", $string); echo $string; die(); ?> Should leave you with %$%. Quote Link to comment https://forums.phpfreaks.com/topic/155854-sql-query-to-strip-all-non-a-z0-1-characters/#findComment-820603 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.