X characters before and after PHP search keywords-php Tutorial

Source: Internet
Author: User
How can I search for 50 characters before and after the keyword in PHP?
$ Content = strip_tags ($ content );
Preg_match ("/[^ u4e00-u9fa5] {} {$ keyword} [^ u4e00-u9fa5] {}/", $ content, $ m );
This is my original practice, and garbled characters will appear.


$ Keyword = "satisfied"; $ content = <
 

Service

We have always made work and welfare an important part of our comprehensive service delivery households, and are committed to the design order. test will meet the customer's needs, while saving costs and ensuring a high level of service providers.

Our work and welfare team will learn from you that your specific company needs to design a plan from the division and drawing components to meet your staff #39; needs, at the same time, keep in line with your strategy, budget, and market practices.

We need to actively participate in your staff welfare plan and implementation process. We hope to share with you a long-term approach to rethink the overall welfare strategy and help restore and improve the reality and feeling of the plan.

 

EOT;


Reply to discussion (solution)

 preg_match("/[\w\W]{1,90}{$keyword}[\w\W]{1,90}/u", $content, $m);

 preg_match("/[\w\W]{1,90}{$keyword}[\w\W]{1,90}/u", $content, $m);



There will be a bunch of spaces in front of some matched content

Then you can remove the space before matching.

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.