PHP search keywords before and after x characters

Source: Internet
Author: User
How to search the keyword 50 words before and after?
$content = Strip_tags ($content);
Preg_match ("/[^u4e00-u9fa5]{1,90}{$keyword}[^u4e00-u9fa5]{1,90}/", $content, $m);
This is my original practice, there will be garbled


$keyword = "satisfied"; $content = <<
 <>

Service

We have been delivering the services as a key component of the integrated service delivery to the design sequence, test will meet the needs of customers, while real cost savings and ensure a high level of service providers.

Our engineering and welfare team will work with you to understand your specific business needs to design a plan from the Division and drawing components to meet your employees # 39; requirements while maintaining compliance with your strategy, budget and market practices.

We will actively participate in your staff welfare program and the implementation process. We hope that with your long-term approach, re-think the whole welfare strategy, help the complex and improve the reality and feel 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 the matched content.

Then you can match the space after you remove it.

  • 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.