How do I parse a string between two characters?
I have a string:
"somethingsomething-13-24"
I want to make two variables out of this: the "13" and the "24". The first set of characters will always be between two dashes (-). The second set will be after the second dash to the end of the string.
How would I do this with PHP?
Thanks.
PHP Code:
$string = 'somethingsomething-13-24' ; list( $one , $two ) = array_slice ( explode ( '-' , $string ), - 2 ); echo "one: $one , two: $two " ; // one: 13, two: 24
Mindzai, I owe you one. Thanks!
Best solution ever.
Actually, let's say that I want to keep the "somethingsomething" also. How would I do that?
PHP Code:
$string = 'somethingsomething-13-24' ; list( $something , $one , $two ) = explode ( '-' , $string );
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks