I currently fetch a GET-param via PHP and run through at PHP function. Now I need that value for a jQuery script on the site. So how can I do the following in jQuery?
function trimQuery($query){
$query = trim($query);
$query = preg_replace("/[^a-zåäö0-9\s]/i","",$query);
return $query;
}
$trimmedQuery = trimQuery($_GET['q']);
$arrayTrimmedQuery = explode(" ",trimmedQuery );
foreach(arrayTrimmedQuery as $value){
echo $value;
}
Here you go, I have kept the same code structure and variable names. This function is pure JavaScript (without any jQuery function).