PHP search function

Source: Internet
Author: User
PHP search function $ keywordk = "key"; // keyword
$ SQL = sprintf ("select id from table where content like '% s %'", $ keywork)
$ Retult = $ SQL result

1. if the content contains keywords, the corresponding id will be identified.
Because content is used to save the content of the editor. if there is something like this in it, it will be detected.
(The search display page does not display images. if the keyword is not found in the tag, how can this problem be solved ?)

2. query the question about 70 characters before and after the paragraph where the keyword is located
Because it is the editor, I used the tag.

$ 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 );

The detected content contains line breaks and garbled characters.


Reply to discussion (solution)

Save the edited content in the editor. it is normal to have a line break.
Split the string. UTF-8 is a Chinese character. if a Chinese character is separated from the middle, it will be garbled.

Utf occupies three to four characters... So we need to change the cutting method.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.