Exploding a string
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);
精彩评论