oracle259 Posted September 23, 2006 Share Posted September 23, 2006 Not certain which forum this belongs in but here goes. How can I explode numbers and symbols from a mysql query.eg. if i have a table with column pwd which contains 2 row with the following information:w2@%Def1IP!4mbn3tj45#m%$nt ??? how do i go about exploding the numbers and symbols to get a result that gives me the following output:array("wDefIPm","bntjmnt")If you have any suggestions i would really appreciate it Link to comment https://forums.phpfreaks.com/topic/21749-exploding-and-mysql-arrays/ Share on other sites More sharing options...
akitchin Posted September 23, 2006 Share Posted September 23, 2006 first of all, you're not looking for exploding. exploding breaks up a string into an array based on what you're exploding with; that is, you're splitting up the string based on a delimiter.second, a simple str_replace() should work for your purposes. load all of your unwanted characters into an array and replace them with nothing:[code]<?php$unwanted_characters = array( '!', '@', '#', '$');$replacees = array_merge(range(0, 9), $unwanted_characters);$actual_password = str_replace($replacees, '', $stored_password);?>[/code]this will automatically include digits, so just add all the other characters you want to get rid of into that $unwanted_characters array. look up the function, it's useful. Link to comment https://forums.phpfreaks.com/topic/21749-exploding-and-mysql-arrays/#findComment-97125 Share on other sites More sharing options...
oracle259 Posted September 23, 2006 Author Share Posted September 23, 2006 Ok i read up on str_replace and ur right its exactly what i was looking for. But im still somewhat confused so let me tell u what im tryin to do. Basically, i need a function that would check a userid for profanity eg fshit.%4m would not be accepted as a proper userid. The banned words would be stored in a mysql database and userids would be checked against it. Ok now need to know if im on the right track with the following code:<?php$sql = "SEARCH profanity FROM filter";$result = @mysql_query($sql);while ($words = @mysql_fetch_array($result, MYSQL_BOTH) {$profanity[] = $words[profanity];}$kill_characters = array ('.', '-', '_');$kill_num = range(0,9);$kill_all = array_merge($kill_num, $kill_characters);$userid = str_replace($kill_all, '' ", $userid);$obscene = $profanity[];foreach ($obscene as $obscenities) { if (stristr(trim($userid), $obscenities)) { $match = similar_text($userid, $obscenities, $percent); $percent = round($percent, 2); if ($percent >= '50') { echo "Sorry, username <b>$userid</b> is too vulgar. Please select another username.";} else {echo "Congratulations, username <b>$userid</b> is available.";}} else {echo "Congratulations, username <b>$userid</b> is available.";}}?>Where am i going wrong? ??? Link to comment https://forums.phpfreaks.com/topic/21749-exploding-and-mysql-arrays/#findComment-97131 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.