-1

I have a string like this:

[Rise] and rise [again] until lambs become [lions].

I want to get all the string inside the [] (Rise, again, lions) and put it in to an array. How can I do this?

Edit: Thank you guys, I already found the solution here: PHP: Best way to extract text within parenthesis?

4
  • can you show the array struture where you have those keys ? Commented Jun 8, 2019 at 13:34
  • 1
    Close the question by deleting it or post your edit as an answer and accept it. Commented Jun 8, 2019 at 14:52
  • 1
    @Matt I think it's easier to just flag the question as a duplicate. Commented Jun 8, 2019 at 14:59
  • @Matthew True, forgot about that haha Commented Jun 8, 2019 at 15:13

1 Answer 1

1

You can do it with regular expressions:

$s = '[Rise] and rise [again] until lambs become [lions].';

preg_match_all('/\[([^\]]+)\]/', $s, $m);
print_r($m[1]);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.