|
Posted by Alan Little on 05/18/06 04:23
Carved in mystic runes upon the very living rock, the last words of ImOk
of comp.lang.php make plain:
> I have this PHP statement which works fine and breaks down a string of
> lines delimited with a \r into an array.
>
> $arrList=split("\r", $strList);
>
> But what I really want is to be able to tell it to split out only the
> strings that start with the letter "b".
>
> E.g. I thought this would work "b\W\r"
>
> I tried every regular expression but cant figure it out. I could use
> some other function combinations to achive this but I though if there
> is a way to do it with just spli()
Since split() deletes the delimiter string that it's splitting on, I
don't think that function is going to give you what you want, regardless
of regex.
Try the preg_match_all() function.
An alternative would be to convert the appropriate \r characters to
something else unlikely to be in the string (such as a \3, for example),
and split on that:
$strList = preg_replace("/(b.+)\r/U", "\\1\3", $strList);
$arrList = explode("\3", $strList);
--
Alan Little
Phorm PHP Form Processor
http://www.phorm.com/
[Back to original message]
|