Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

How to capture the first number along with all text after it in string

$
0
0

I'm looking for a way to find and capture the first number and all text after it in a string.

 

Examples:

 

I have the following entries:

 

some text 23 text

sometext 21

sometext some text 120 text

 

I want the script to capture the number, and everything after it, and put it into a variable. At the same time, the captured part should be removed from the original string.

 

So the above examples whould be:

 

some text 23 text >> some text | 23 text

sometext 21 >> sometext | 21

sometext some text 120 text >> sometext some text | 120 text

 

How can this be done? I was suggested to use preg_match, but i can't figure out how to write that to do what I want.


Viewing all articles
Browse latest Browse all 13200

Latest Images

Trending Articles



Latest Images