Does anyone know if there is a function to split a string as follows.
Code: Select all
$string"DATA 1: testa DATA 2: testb DATA 3: testc";So I want to be able to somehow explode the string between two seperators [: and a space].
Many thanks,
Rob.
Moderator: General Moderators
Code: Select all
$string"DATA 1: testa DATA 2: testb DATA 3: testc";Code: Select all
explode(': ', $string);robburne wrote:Code: Select all
$string"DATA 1: testa DATA 2: testb DATA 3: testc";
Code: Select all
$parts = preg_split('/DATA[\d]+\:/', $string);Code: Select all
$parts = preg_split('/DATA[\s]+[\d]+:/', $string);That's exactly what the script does.robburne wrote:Ok thanks for the explanation that makes sense now........
However I am not sure if you have mis-readmy intentions. I need to search for data betweentwo seperators. So that on this string.....
$string"DATA 1: testa DATA 2: testb DATA 3: testc";
I am extracting testa, testb and testc.
I am guessing I want to search for data between a colon symbol and the word data?
Rob.
Do you mean...robburne wrote:Hi,
Using your exact code I amgetting no output.
Rob.
Code: Select all
<?php
$string = 'DATA 1: testa DATA 2: testb DATA 3: testc';
$parts = preg_split('/DATA[\s]+[\d]+:/', $string);
print_r($parts);
?>Code: Select all
echo"$message";Code: Select all
This is a multi-part message in MIME format. ------=_NextPart_000_0170_01C5F46A.2EED1FD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable POD TIME: 18:58 POD DATE: 18th Jan 2005 POD REF: 123456789 POD NAME: R Burne ------=_NextPart_000_0170_01C5F46A.2EED1FD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
POD TIME: 18:58
POD DATE: 18th Jan 2005
POD REF: 123456789
POD NAME: R = Burne
------=_NextPart_000_0170_01C5F46A.2EED1FD0--Code: Select all
$parts = preg_split('/DATA[\s]+[\d]+:/', $message);Code: Select all
Array ( [0] => This is a multi-part message in MIME format. ------=_NextPart_000_0170_01C5F46A.2EED1FD0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable POD TIME: 18:58 POD DATE: 18th Jan 2005 POD REF: 123456789 POD NAME: R Burne ------=_NextPart_000_0170_01C5F46A.2EED1FD0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
POD TIME: 18:58
POD DATE: 18th Jan 2005
POD REF: 123456789
POD NAME: R = Burne
------=_NextPart_000_0170_01C5F46A.2EED1FD0-- )Code: Select all
$keywords = preg_split("/A+C/", "ABCDEF");
print_r($keywords);Code: Select all
Array ( [0] => ABCDEF )Code: Select all
$time=preg_split("/\d{2}.\d{2]/", $message);