|
查看: 1055|回复: 5
|
php : 类似google 搜索结果, 搜索了一段, 结果太长了, 如何只拿一部分?
[复制链接]
|
|
|
类似google 搜索结果, 搜索了一段, 结果太长了, 如何只拿一部分? 谢谢
 |
|
|
|
|
|
|
|
|
|
|
发表于 16-4-2011 10:38 AM
|
显示全部楼层
mysql 的 SUBSTRING  |
|
|
|
|
|
|
|
|
|
|

楼主 |
发表于 17-4-2011 11:24 PM
|
显示全部楼层
本帖最后由 MadD 于 17-4-2011 11:38 PM 编辑
我写了以下的方法收索
http://tapiv.zxq.net/ma/string7.php
可是在 highlight 时有些问题, 代码如下:
$text = str_ireplace($_GET, '<span class="highlight_word">'.$_GET.'</span>', $text);
如$_GET 是 new (小写), str_ireplace 将把文章大写的都换成了小写, 如何是好? 谢谢。
 |
|
|
|
|
|
|
|
|
|
|
发表于 18-4-2011 09:58 AM
|
显示全部楼层
- $text = str_ireplace($_GET, '<span class="highlight_word">'.$_GET.'</span>', $text);
复制代码 因为你是拿user type下去的keyword来search 所以当然出来的result就是这样咯。。
你应该拿文章里面的字先。。在来highlight吧~ |
|
|
|
|
|
|
|
|
|
|
发表于 18-4-2011 11:40 AM
|
显示全部楼层
用preg_replace- <?php
- $search = 'new';
- $text = 'NEW something new something New something newer knew something';
- $meta = '/([\\\^\$\.\[\]\|\(\)\*\+\{\}\-])/';
- $pattern = '/\b' . preg_replace( $meta, '\\\\$0', $search ) . '\b/i';
- $text = preg_replace( $pattern, '<span class="highlight_word" style="color:red;" >$0</span>', $text );
- print_r( $text );
- //<span class="highlight_word" style="color: red;">NEW</span> something <span class="highlight_word" style="color: red;">new</span> something <span class="highlight_word" style="color: red;">New</span> something newer knew something
复制代码 |
|
|
|
|
|
|
|
|
|
|
发表于 18-4-2011 03:19 PM
|
显示全部楼层
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|