how can I split this string:
|^^^*|^^^*|^^^*|^^^*|^^^*|myvalue^nao^nao^nao*|myvalue^nao^nao^nao*|myvalue^nao^nao^nao*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*|^^^*
so I can only get the value "mayvalue".
For the mo开发者_开发知识库ment, I'm using:
$text = preg_split("/[^\|(*.?)\^$]/", $other);
But it returns myvalue^nao
Any ideas?
You could split twice, once on |
and again on ^
; if your big string is in $input
, then:
$pipes = preg_split('/\|/', $input);
$want = preg_split('/\^/', $pipes[6]);
Then $want[0]
has what you're after. This would probably be easier than trying to come up with one regex to split with.
Demo: http://ideone.com/pxvay
Since shesek hasn't come back I'll include their suggested approach. You can also use explode
twice since you're working with simple delimiters:
$pipes = explode('|', $input);
$want = explode('^', $pipes[6]);
and again $want[0]
has what you're looking for.
And a demo of this approach: http://ideone.com/SwGEH
This will get all "myvalue" and other strings placed after |
and before ^
in an array, $matches[1]
:
$text = preg_match_all("/\|(.*?)\^.*?\^.*?\^.*?\*/", $other, $matches);
精彩评论