开发者

Exploding a string

开发者 https://www.devze.com 2023-01-11 00:20 出处:网络
What I am trying to achieve is to explode a string into an array as follows: $arr = explode(\'<some_tag></some_tag>\', $str);

What I am trying to achieve is to explode a string into an array as follows:

$arr = explode('<some_tag></some_tag>', $str);

But I want to explode it even if there might be som开发者_StackOverflow社区ething between the tags:

$str = '<some_tag>text<some_tag>');

Could you please suggest how to settle down the problem?


Given the information you've provided, I can only guess at what you want, but it looks like you're trying to parse XML. If that's the case, I would suggest giving SimpleXML a try.

http://php.net/manual/en/book.simplexml.php

It comes standard with PHP, but there are some minor bugs in early versions of PHP 5.


You can use preg_split() to split a string by a pattern:

$arr = preg_split('!<some_tag>(.*?)</some_tag>!', $str);
0

精彩评论

暂无评论...
验证码 换一张
取 消