I have spent about a couple of hours trying to read the pcre regex syntax on the php.net manual but I can't for the love of god grasp the concept of it. If anyone can help me it would be greatly appreciated.

I'm trying to split some strings into an array and I dont THINK that explode() would work since I wanna split this $str = '[str1][str2][str3]' into Array([0]=>'str1', [1]=>'str2', [2]=>'str3') I could use preg_split() or preg_match() and use the $match variable but I just don't know how to set the pattern that get the strings inside the [].

please help >_<

7 Years
Discussion Span
Last Post by kekkaishi

You could look for any number of characters ( [a-z0-9]* ) between '' in a preg_match_all. If the string within the brackets are always 'str' and then a number, you could also search for str[1-9] in a preg_match_all.

You could also use explode if you first replace one of the square brackets with nothing and then use the other bracket to explode the resulting string.

Hope you understood.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.