原定义标签tex=type,之后直接改为type
用以下代码修改数据库
<?php $host = "localhost"; $user = "user"; $pwd = "pass"; $connID = mysql_connect($host, $user,$pwd); mysql_select_db("tecbbs", $connID); $query = mysql_query("select pid,message from pre_forum_post where message like '%[/tex]%'", $connID); $sum = 0; $pids = array(); while($data = mysql_fetch_array($query)) { $pids[$data["pid"]] = $data["message"]; } //print_r($post); $pattern = array( "/\[tex=gv\](.+?)\[\/tex\]/s", "/\[tex=gv,([\w]+)?\](.+?)\[\/tex\]/s", "/\[tex=code\](.+?)\[\/tex\]/s", "/\[tex=md\](.+?)\[\/tex\]/s", "/\[tex=m\](.+?)\[\/tex\]/s", "/\[tex=go\](.+?)\[\/tex\]/s", "/\[tex=xiti\](.+?)\[\/tex\]/s", ); $replace = array( "[gv]\${1}[/gv]", "[gv=\${1}]\${2}[/gv]", "[pre]\${1}[/pre]", "[md]\${1}[/md]", "[math]\${1}[/math]", "", "[goxiti]\${1}[/goxiti]", ); foreach($pids as $k => $val) { $post = str_replace("\\", "\\\\", $val); $post = preg_replace($pattern, $replace, $post); $data = mysql_query("update pre_forum_post set message='" . $post . "' where pid=$k", $connID); print_r($post); }
发表回复