function pregmessage($message, $rule, $getstr, $limit = 1) { $result = array('0' => ''); $rule = convertrule($rule); //转义正则表达式特殊字符串 $rule = str_replace('\\[' . $getstr . '\\]', '\\s*(.+?)\\s*', $rule); //解析为正则表达式 if ($limit == 1) { preg_match("/{$rule}/is", $message, $rarr); if (!empty($rarr[1])) { $result[0] = $rarr[1]; } } else { preg_match_all("/{$rule}/is", $message, $rarr); if (!empty($rarr[1])) { $result = $rarr[1]; } } return $result; }
function stringreplace($replace, $replaceto, $message) { if (is_array($replace)) { foreach ($replace as $key => $val) { $message = stringreplace($val, $replaceto[$key], $message); } } else { if (!empty($replace)) { $rule = convertrule($replace); if (strpos($replaceto, '[string]') === false) { $replacestr = $replaceto; } else { $replacestr = str_replace('[string]', "\${1}", $replaceto); } $message = preg_replace("/({$rule})/s", $replacestr, $message); } } return $message; }