Preg_Replace and Capture Value? PHP

ptc187

New Member
I'm building a filter plugin in Wordpress and I'm replacing some plugin specific tags with bits of html.Example: [VIDEO ID=12] will be replaced via preg_replaced in this function\[code\]function display_video($text){ $pattern = '/\[VIDEO ID\=\d+\]/'; $text=preg_replace($pattern,get_video_block($id),$text); return $text;}\[/code\]I'm not exactly sure how to make sure I supply the correct ($id) param to my get_video_block function for each replacement occurrence.There's no real loop going on other than inside the preg_replace function so, how would I supply that value?Thoughts?EDIT (get_video_block) function:\[code\]function get_video_block($id){ global $wpdb; $wpdb->show_errors(); $table_name = $wpdb->prefix . "video_manager"; $query = "SELECT * FROM " . $table_name . " WHERE `index` = '$id'"; $results = $wpdb->get_results($query, ARRAY_A); $results = $results[0]; $returnString = '<div class="vidBlock">'; $returnString .= $results['embed_code']; $returnString .= '<div class="voteBar">'; $returnString .= $results['vote_text']; $returnString .= '<input type="button" value="http://stackoverflow.com/questions/3568229/YES" class="voteButton">'; $returnString .= '<input type="button" value="http://stackoverflow.com/questions/3568229/NO" class="voteButton">'; $returnString .= '</div>'; $returnString .= $results['title'] . '<br>'; $returnString .= $results['description'] . '<br>'; $returnString .= '</div>'; return $returnString;}\[/code\]
 
Back
Top