php - preg_match_all error when pattern is a variable in YII -


i have table called dictionary, in has words want find in text being pulled table. i'm using preg_match_all match words in text. have tried many different solutions found online, no luck far. seems problem when create variable $pattern hold text, please see code below. appreciated.

  <?php $words=  dictionary::model()->findallbysql("select word tbl_dictionary ");?> <?php foreach ($words $word): ?>          <?php  //$matches = array()?>         <?php  $string =$data->text_content; $pattern = "/\b($string)\b/" ; preg_match('.$pattern.', $word->word, $match);?>           <?php echo var_dump($match); ?>            <?php endforeach  ;?> 

i doing wrong way round. variable $pattern should have words looking , $word->word should $data->text_content. purified $data->text_content

<?php $words=  dictionary::model()->findallbysql("select word tbl_dictionary ");?>         <?php foreach ($words $word): ?>            <?php  //$matches = array()                          $chtmlpurifier = new chtmlpurifier();                          $chtmlpurifier->options = array('html.forbiddenelements' => array('br, p, img,&lt'));                         $purified = $chtmlpurifier->purify($data->text_content);              preg_match( "/$word->word/", $purified, $match);            ?>            <?php echo var_dump($match); ?> 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -