String search based on two seperators?
Moderator: General Moderators
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
\d ......Any single digit (0-9)
/\d{4}/ ......we can specify how many times a character should occur
Therefore I see no reason why this won't work....
/\d{4}/ ......we can specify how many times a character should occur
Therefore I see no reason why this won't work....
Code: Select all
$time=preg_split("/\d{2}.\d{2]/", "18.58");Code: Select all
<?php
$string = "DATA 1: testa DATA 2: testb DATA 3: testc";
$values = preg_split("/DATA \d+\: /", $string);
array_shift($values);
print_r($values);
?>Whaddya know... it's in the PHP Manual!robburne wrote:What is PCRE?
Thanks for taking the time to RTFM!
I'm not going to let you off the hook that easily this time. Go through your code step by step. If you can't figure it out, get The Regex Coach and input the pattern. See what it tells you.robburne wrote:Code: Select all
$time=preg_split("/\d{2}.\d{2]/", "18.58");
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm
Thanks for the feedback, ok so it seems i have a typo in my expression . duh!
So with the change I am starting to get somewhere becuase.....
Is giving me...........
"POD TIME: "
So I think this show I understand the regex, just that I am not using the function correctly as I wantthe second half of the expression not the first.
Rob.
So with the change I am starting to get somewhere becuase.....
Code: Select all
$time=preg_split("/\d{2}.\d{2}/", "POD TIME: 18.00 ");"POD TIME: "
So I think this show I understand the regex, just that I am not using the function correctly as I wantthe second half of the expression not the first.
Rob.
Last edited by spacebiscuit on Tue Nov 29, 2005 3:00 pm, edited 1 time in total.
Good. The function you'll want to use is preg_match_all(). What you are doing now, is splitting your string along each occurrence of two numbers separated by a dot. Using preg_match* you'll retrieve those numbers instead.robburne wrote:Thanks for the feedback, ok so it seems i have a typo in my expression . duh!
So with the change I am starting to get somewhere becuase.....
Is giving me...........Code: Select all
$time=preg_split("/\d{2}.\d{2]/", "POD TIME: 18.00 ");
"POD TIME: "
So I think this show I understand the regex, just that I am not using the function correctly as I wantthe second half of the expression not the first.
Rob.
-
spacebiscuit
- Forum Contributor
- Posts: 390
- Joined: Mon Mar 07, 2005 3:20 pm