alpineedge3 Posted July 28, 2006 Share Posted July 28, 2006 i have a php script that searches a mysql database using terms from a user input box. i want to have a script that will extract "words" (or alphanumeric groupings) from the string and put them into an array. i don't want to create the array based on a string separated by spaces (' ') because that is not secure. what's the best way to do this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/15850-extract-only-words-from-search-string-for-security/ Share on other sites More sharing options...
effigy Posted July 28, 2006 Share Posted July 28, 2006 [code]<?php $string = <<<STR one fish two fish red fish blue fish. word1 word2 word3. #$#%^A b&*.- +1230STR; preg_match_all('/\b[a-z0-9]+\b/i', $string, $array); echo '<pre>', print_r($array, true), '</pre>';?>[/code]Outputs:[tt]Array( [0] => Array ( [0] => one [1] => fish [2] => two [3] => fish [4] => red [5] => fish [6] => blue [7] => fish [8] => word1 [9] => word2 [10] => word3 [11] => A [12] => b [13] => 1230 ))[/tt] Quote Link to comment https://forums.phpfreaks.com/topic/15850-extract-only-words-from-search-string-for-security/#findComment-64986 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.