View Single Post

  #2 (permalink)  
Old 10-28-2004
Oli Filth
 
Posts: n/a
Default Re: preg_replace question

This splits the string as you intended, I'm assuming you want the
headings kept with their respective information sections? I don't think
you can do that directly with preg_split, but if you do:

$Results = preg_split('/^\S+/m', $string, -1, PREG_SPLIT_DELIM_CAPTURE);

$Results will look something like:

$Results[0] = "heading1"
$Results[1] = "information1..."
$Results[2] = "heading2"
$Results[3] = "information2..."
etc.

Now all you need to do is concantenate $Results[0] with $Results[1],
$Results[2] with $Results[3], and so on.

Hope this helps,
Oli


Fred Emmott wrote:
> I have a string containing something like this:
>
> heading1
> information
> ...
> ...
> heading2
> information2
> ...
> ...
>
> etc - i'm wanting to split this into an array each containing one section.
> Here's what i'm trying: preg_split('/^\S+/m', $string) - this isn't
> working. any suggestions?
>
> Thanks,
>

Reply With Quote