php - preg_replace() find matches in MySQL Table -


    function convtext($v){      $str = htmlentities($v);      preg_match_all('(\[\[(.+?)\]\])', $str, $matches);      foreach($matches['0'] $match){          $substring = substr($match, 1);         $getdata = bandtolink($substring);         $str = preg_replace('/$match/', $getdata , $str);     }     return $str;     }  function bandtolink($v){      $findband = mysql_query("select * news news_title='". $v ."'") or die(mysql_error());     if(mysql_num_rows($findband)==0){         return '<strong style="color:red">$v</strong>';     } else {         $getfind = mysql_fetch_assoc($findband);         return '<a href="/band/'. $getfind['seo_link'] .'.html">'. $getfind['news_title'] .'</a>';     }  }  $text = "lorem ipsum dolor sit amet, [[apple]] , lorem [[cherry]] ipsum dolor"; echo convtext($text); 

how can replace [[apple]] texts <a href="#">apple</a>, if apple found in database? have using pattern on asp function same works, doesn't work on php.

you forgot include delimiters in regular expression. should be:

preg_match_all('/(\[\[(.+?)\]\])/', $str, $matches); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -