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.