Regex allow alphanumeric + spaces

hi all

just after a little adjustment to this regex if possible
need it to allow a-z, 0-9 and spaces

  $valid = true;
  if (preg_match('/[\\W]/i', $value) $valid = false;

accepts alphanumeric and underscores but returns false when spaces are in

is there a small adjustment that can be made to fix this?
sorry my regex skills are pretty pathetic



preg_match("/\\w|\\s+/", $value)

I did a search on Google and grabbed the answer from here…

\s means whitespace characters

What’s a whitespace character?

a space or newline

or a tab

k thanks guys, i’ll give it a go
whitespace is cool, i’ll only need it for text fields anyway

also, when someone says searched on google
is it possible to say what your search term was
i know that’s asking a lot
but sometimes the right phrase never comes to mind

There is a query string on the end of that link in post #2 with the search terms used (“many characters”). But you’re right, it helps if people let you know what search terms they used. I don’t always know what terms to search on myself. :slight_smile:

nah, that didn’t work
it’s sort of backwards of what i’m trying to do
i am checking to see if there are non-alphanumeric characters except for white space
is there a way to do exceptions in perl regex?
i tried the suggestion
but even with [a-z\s], [\w\s], \w|\s, \w|\s+, nothing
they all still crap on spaces, could i have a setting that’s not set up or something?
i’m running php 5 (installed from binary) on iis

if you do preg_match on $_SERVER[‘HTTP_REFERER’] to see whether its from google, then get the q= part, thats the search terms, you could then mail it to yourself ot add to a database. Heres the script that I use (in the head of a every page)

function referer()
	if(strstr($parts['host'],"google")) { //if they've come from google
		$get=preg_split("#&#",$parts['query']); //get query string of url
		foreach($get as $key=>$stuff) { //put into an array of var=value
		if($get['q']) { //if q= was in the query string
			$search_phrase=$get['q']; //thats the search terms
			if($get['start']) { //if start was set, that indicates what page they ame from
			} else {
				$page=1; //..otherwise it was page 1
			$entry_page=$_SERVER['PHP_SELF']; //mark what page they came in on
			$query="INSERT INTO google_terms VALUES('".$search_phrase."', '".$page."', '".$entry_page."')";
			@mysql_query($query); //put into database

what was this aimed at?

sorry I think I misunderstood

also, when someone says searched on google
is it possible to say what your search term was?

I thought he meant how to tell what people searched for to get to your site, reading it again I see what he means :blush:

he, it was me, nm
yeah, no i would never change the subject in my own thread (just want answers :))
and prolly not in someone else’s