tags:

views:

53

answers:

2
+1  Q: 

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 something between the tags:

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

Could you please suggest how to settle down the problem?

+1  A: 

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

$arr = preg_split('!<some_tag>(.*?)</some_tag>!', $str);
yjerem
+3  A: 

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.

haydenmuhl