General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old January 2nd, 2004, 04:53 AM
weisim weisim is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 11 weisim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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";
)

Reply With Quote
  #2  
Old January 2nd, 2004, 06:35 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
Couple of ways:

PHP Code:
//Pure regular expression matching a la perl
if(preg_match("/ /",$string){
    
//Do stuff.



or


PHP Code:
//Check the parameter order behind me. This'll match basic patterns, case insensitive.
if(eregi(" ",$string)){
    
//Do stuff



or

PHP Code:
//Again, check my parameter order before trying this.
if(strstr(" ",$string)){
    
//Do stuff.



These are in the order I'd be likely to use them, from most flexible to least and arguably from most efficient to least.

Reply With Quote
  #3  
Old January 2nd, 2004, 05:53 PM
Mike_r Mike_r is offline
ExoCrew
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 68 Mike_r User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
How about using \s instead of " "

example

if ( preg_match ( '/(\s)/', $string ) )
{
// dO StUFf
}
__________________
ExoHelpDesk
ExoCrew Free Services

Reply With Quote
  #4  
Old January 3rd, 2004, 10:59 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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".

Reply With Quote
  #5  
Old January 4th, 2004, 04:08 PM
weisim weisim is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2003
Posts: 11 weisim User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
hehe... thanks guys, that was EXACTLY what I needed!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > regular expressioins


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT