preg_replace_all problem

I am basically opening a .tpl file and replaceing the tag's which look like this:
{movies 30}
in the above example "movies" is key and 30 is the value

the problem that I am having is if I have 2 tags that are movies
30 movies: {movies 30}
more movies: {movies 60}

I am getting a double dim array instead of a single one...

heres the code i am using..

$content = join("",file("test.tpl"));  // check template.tpl path

foreach ($categories as $value)
        $pattern = "/{".$value." ([0-9_]+)?}/";

foreach ($matches as $key =>$value)
      $q = "select client from t_members where category_number='".$res[0][0]."' limit ".$value[1][0]."\n";

      echo $q."<br><br>";

       $content = str_replace($matches[$index][0],$value,$content);
      $value ="";
echo "<br>".$content;


*** end code ***

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

preg_match_all returns a multidimensional array, so you also have to loop over that array like this:

foreach ($categories as $value) {
    $pattern = "/{".$value." ([0-9_]+)?}/";

foreach ($matches as $key =>$value) {
    foreach($value[0] as $i => $v) {
        if (empty($v)) {
        $q = "select client from t_members where category_number='".$res[1][0]."' limit ".str_replace('_', ',', $res[1][1])."\n";
        $content = str_replace($value[0][$i],$q,$content);
echo "<br>".$content;


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mag1c1anAuthor Commented:
Hi Hernst42,
Its not working.....can you look at this question as the whole script is written there:

and this question and that one is related....if you can solve it i'll give you the points for both of then...

mag1c1anAuthor Commented:
This is my template file:

And here are some cartoons:<br>
{2 3}
Or if  you prefer full movies:
<br><b>{1 15} </b>
Third and final one:
<br><i>{3 3} </i>
<b>And here come the links 1-15</b>
<br>{textlinks 0_15}

<b>And here come the links 15-30</b>
<br>{textlinks 16_30}

and when i say its not working is because its ignoring
{2 3}  and {3 3}

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.