PHP 搜索功能

WBOY
Release: 2016-06-20 12:27:43
Original
1028 people have browsed it

$keywordk = "key";  // 关键字
$sql = sprintf("select id from table where content like '%%%s%%'", $keywork)
$retult = $sql 结果

1.如果content里包含关键字,就会把对应id查出来
因为content 是保存编辑器内容,如果里面有 PHP 搜索功能  类似这样的也会被查出来
(搜索显示页不显示图片, 如果关键字是标签内的不搜出,这个要怎么解决?)

2.查询出关键字所在段落前后约70个字符时遇到的问题
  因为是编辑器我用了去标签

         $list[$k]['content'] = strip_tags($list[$k]['content']);         $pos = strpos($list[$k]['content'], $keywords);         $list[$k]['content'] = substr($list[$k]['content'], $pos-70<0 ? 0 : $pos, $pos+70);
Copy after login

查出的内容有换行和乱码


回复讨论(解决方案)

保存编辑器编辑的内容,有换行很正常嘛。
分割字符串,utf-8一个中文三个字符,如果一个中文被从中间分割,就乱码了

utf占三到四个字符。。。所以要用换种的切割方式

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template