Re: preg_match_all problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi John,
Thanks for replying.

/*
I see where things are being matched, but how are they being replaced? What
you really need here is preg_replace_callback(), probably.
*/

Most of the RegEx was written by a friend and I just added a bit to it (I am
learning RegExs and still hav not gotten the hang of the basics really)

There is quite a bit of code before I am doing the replaceing thats why I
didnt write that part, i figured the top to be the problem...but heres the
replaceing part that i am using:

$content = str_replace($matches[$index][0],$value,$content);

If you are interested in seeing the whole script, just scroll down.

Thanks,
Ryan







<?php
require "../settings.php";

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

// these are the categories
$categories=array("1","2","3","textlinks");

// This gets the tags and put it into matches[]
 foreach ($categories as $value)
  {
     $pattern = "/{".$value." ([0-9_]+)?}/";
//     if (preg_match($pattern,$content) == 1)
         preg_match($pattern,$content,$matches[]);
  }
//echo "<pre>";
//print_r($matches);
//exit;

$index=0;
// Here we get make the sql statement and execute it
foreach ($matches as $key =>$value){
     preg_match("/\w+/",$value[0],$res);

print_r($res);
//print_r($value);
//echo "</pre>";
##exit;


if($res[0] != "textlinks")
 {
  $query = "select
client_id,category,gallery_url,description,thumb_name,has_thumb from
t_members where category_number='".$res[0]."' limit ".$value[1]."\n";

//echo $query."<br><br>";
//exit;

 $value ="";
 $result = mysql_query($query);

      while ($row = mysql_fetch_row($result))
   {
   $client_id = $row[0];
   $category = $row[1];
   $gallery_url = $row[2];
   $description = $row[3];
   $thumb_name = $row[4];
   $has_thumb = $row[5];
   $value .= $client_id." ".$category." ".$gallery_url." ".$description."
".$thumb_name." ".$has_thumb."<br><br>\n\n ";
   }


 }
 else
 {
//  echo "in here";
 $limit=explode("_",$value[1]);
  $query = "select gallery_url,description from t_members limit
".$limit[0].",".$limit[1];

 $value ="";
 $result = mysql_query($query);

   while ($row = mysql_fetch_row($result))
      {
   $gallery_url = $row[0];
   $description = $row[1];
   $value .= "<a href='".$gallery_url."'>".$description."</a><br>\n\n";
   }
//echo $query;
 }



//echo "<b>r".$matches[$index][0]."</b>";

  $content = str_replace($matches[$index][0],$value,$content);
  $index++;
}


echo "<br>".$content;
?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux