Question:

In PHP, I want to extracting text between brackets and throw it into an array.

by  |  earlier

0 LIKES UnLike

I have a string:

$string = "Hi there {name}. I like to eat {fruit}.";

I want to get the following output:

([0] => "name", [1] => "fruit")

I thought I could use preg_split, but it doesn't seem to work.

$array = preg_split('/{([^}]*)}/', $string);

Please help.

 Tags:

   Report

1 ANSWERS


  1. try preg_match_all the results are automaticly stored into an array

    http://uk3.php.net/manual/en/function.pr...

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions