从关键字前面的第一个"."或" "开始截取.<?php$text = "啊啊啊啊啊啊啊,adafasf.aaaaaaaa.自动司法俄ccc,adfladsfoaeofsdf,asdfadsf.";
$length = 20;
$keyword = "ccc";$pattern = "|([^ .]*$keyword.{{$length}})|";
preg_match($pattern, $text, $match);
echo substr($match[0], 0, $length);?>
$length = 20;
$keyword = "ccc";$pattern = "|([^ .]*$keyword.{{$length}})|";
preg_match($pattern, $text, $match);
echo substr($match[0], 0, $length);?>
然后从这个起点截取200。
PHP我没有做过。我只是用ASP实现过。
$match是处理后得到的结果数组这么说我理解,可是我这里$match为什么得不到结果数组呢,而且如果遇到包含的关键字不在前200个字节的时候它内容就什么也不显示了,那些在前200个字节里包含关键字的还会显示
获得关键字位置后来截取字符串的,不过还是谢谢各位哦