|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
regular expressioins
Hi peoples,
yet another question. OK I don't REALLY understand regular expressions, but I know that that is how I'm supposed to write this code snippet. I was just wondering, if I want to write a snippet of code that checks wether a string has spaces in it or not, how would I go about doing it?for exampe, if I said $string = "this is a string"; how could I test wether there was spaces in it? (as opposed to: $string = "this_is_a_string"; ) |
|
#2
|
||||
|
||||
|
Couple of ways:
PHP Code:
or PHP Code:
or PHP Code:
These are in the order I'd be likely to use them, from most flexible to least and arguably from most efficient to least. |
|
#3
|
|||
|
|||
|
How about using \s instead of " "
example if ( preg_match ( '/(\s)/', $string ) ) { // dO StUFf } |
|
#4
|
||||
|
||||
|
Sure, you can do that. Doesn't really matter either way as far as I know, and I figured " " would make more sense to a regex newbie than "\s".
|
|
#5
|
|||
|
|||
|
hehe... thanks guys, that was EXACTLY what I needed!
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > regular expressioins |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|