PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me



Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
Old July 29th, 2005, 10:09 AM
everythingrock everythingrock is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Los Angeles, CA, USA
Posts: 50 everythingrock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to everythingrock
Find first number in string

Hey,

What I'm trying to do is have my code find the first number in a string, and then go find the first letter after that number.. So, say I had this:

8 Hello

I want the code to remove everything up until the H. And if I had:

test 7 Word

It would remove everything up until the W.


I hope that makes sense. Any help would be great. Thanks!

Nick

Reply With Quote
Old July 29th, 2005, 12:28 PM
scaRFhogg scaRFhogg is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Bochum, NRW, Germany, EU
Posts: 117 scaRFhogg User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to scaRFhogg
RE: Find first number in string

php Code:
Original - php Code
  1.  
  2.  
  3. $str = 'test 7 Word';
  4. if(preg_match('/^([^0-9]+[0-9]+ [a-zA-Z])(.+)/', $str, $result))
  5. {
  6.     echo $result[2];
  7. }
  8.  


That matches a string that starts with any number of characters which are not a number then a number and a space then a single letter. Everything that follows is saved in the variable $result[2]

Reply With Quote
Old July 29th, 2005, 11:13 PM
everythingrock everythingrock is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Los Angeles, CA, USA
Posts: 50 everythingrock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to everythingrock
RE: Find first number in string

Thanks... that's a start...

The thing is that sometimes there will be a different number of spaces between the number and the word following it... that code you gave me will only work if there is one space.

Any further help? Thanks,

Nick

Reply With Quote
Old July 29th, 2005, 11:21 PM
everythingrock everythingrock is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Los Angeles, CA, USA
Posts: 50 everythingrock User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via AIM to everythingrock
RE: Find first number in string

Nevermind.. I think I figured it out myself based on what you gave me and some other code I had.

Thanks for your help!

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > Find first number in string


Developer Shed Advertisers and Affiliates


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 | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.

© 2003-2014 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap