PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Sep 25, 2018 1:03 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Sun Sep 29, 2013 11:53 am 
Offline
Forum Newbie

Joined: Sat Aug 31, 2013 7:48 am
Posts: 3
This is my string:

Game: club 1 - Club2, Result: 4 - 2, Set: 2-1, 3-1, 2-1

I want to break these by a PHP preg_match in the next peaces:
- 1: club 1 - Club2
- 2: 4 - 2
- 3: 2-1
- 4: 3-1
- 5: 2-1

The length depends a little because it can be 3 sets but also 5 sets.

I have tried this:
$regex = "#Game: (.*)(\s\-\s)(.*),#"

I tried some more alternatives but it doesn't give the result what I like.

But that doesn't give me the result what I want.

Can somebody give me an idea how to get this result? It may also in three steps like:
1 step only: [0] Club 1 - Club 2
2 step result: [0] 4 -2
3 step set: [0] 2-1 [1] 3-1

Nico


Top
 Profile  
 
PostPosted: Sun Sep 29, 2013 1:00 pm 
Offline
Moderator
User avatar

Joined: Tue Nov 09, 2010 3:39 pm
Posts: 6424
Location: Montreal, Canada
explode() seems like a better choice than regular expressions here.

_________________
Supported PHP versions No longer supported versions


Top
 Profile  
 
PostPosted: Mon Sep 30, 2013 4:50 pm 
Offline
Site Administrator
User avatar

Joined: Wed Aug 25, 2004 7:54 pm
Posts: 13577
Location: New York, NY, US
Yes, explode()ing on space and then reassembling the parts might be easier. Use trim(), rtrim(), ltrim() to remove commas.

_________________
(#10850)


Top
 Profile  
 
PostPosted: Wed Oct 02, 2013 11:05 am 
Offline
Forum Newbie

Joined: Sat Aug 31, 2013 7:48 am
Posts: 3
Yes, I did it with explode.

Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group