Blogger Information
Blog 250
fans 3
comment 0
visits 321824
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
如何用正则表达式匹配QQ表情
梁凯达的博客
Original
1361 people have browsed it

// var_dump($_POST);
 // echo '<img src="./qq/01.gif">';
 // echo '<img src="./qq/02.gif">';
 // echo '<img src="./qq/03.gif">';
 // echo '<img src="./qq/04.gif">';
 // echo '<img src="./qq/05.gif">';
 // echo '<img src="./qq/06.gif">';
 // echo '<img src="./qq/07.gif">';
 // echo '<img src="./qq/08.gif">';
 // echo '<img src="./qq/09.gif">';
 // echo '<img src="./qq/10.gif">';
 //正则表达式数组
 //每个单元都有一个正则表达式
 $preg = array(
   '/\[可怜\]/',
   '/\[哭\]/',
   '/\[起飞\]/',
   '/\[李想\]/',
   '/\[三金\]/',
   '/\[狗哥\]/',
   '/\[奇奇\]/',
   '/\[超超\]/',
   '/\[霄霄\]/',
   '/\[令锋\]/',
  );
 //要替换的内容
 //每个单元都有对应的关系对应每个正则表达还是
 $replace=array(
  '<img src="./qq/01.gif">',
  '<img src="./qq/02.gif">',
  '<img src="./qq/03.gif">',
  '<img src="./qq/04.gif">',
  '<img src="./qq/05.gif">',
  '<img src="./qq/06.gif">',
  '<img src="./qq/07.gif">',
  '<img src="./qq/08.gif">',
  '<img src="./qq/09.gif">',
  '<img src="./qq/10.gif">',
  ); 

 //字符串替换
 $qq = $_POST['qq'];
 $result = preg_replace($preg,$replace,$qq);
 echo $result;

------

表单部分:

<!DOCTYPE html>
<html>
<head>
 <meta charset="UTF-8">
 <title>Document</title>
</head>
<body>
 <form action="doqq.php" method="post">
 <input type="text" name="qq"><br/>
 <input type="submit" value="发送">
 </form>
</body>
</html>

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post