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,<')); $purified = $chtmlpurifier->purify($data->text_content); preg_match( "/$word->word/", $purified, $match); ?> <?php echo var_dump($match); ?>
Comments
Post a Comment