PHP regular match for strings

Source: Internet
Author: User
This article mainly introduces PHP for the string of regular matching, interested in the friend's reference, I hope to be helpful to everyone.

The implementation method is as follows:

/** * Is_external_link detects if string contains outer chain * @param string $text literal * @param string $host domain name * @return Boolean    false has an outer chain true No outer chain */function all_external_link ($text = ", $host =") {  if (empty ($host)) $host = $_server[' http_host '];  $reg = '/http (?: S?): \ /\/((?: [A-za-z0-9-]+\.) +[a-za-z]{2,4})/';  Preg_match_all ($reg, $text, $data);  $math = $data [1];  foreach ($math as $value) {    if ($value! = $host) return false;  }  return true;}

Summary : The above is the entire content of this article, I hope to be able to help you learn.

Related recommendations:

PHP implementation of integrated Discuz user approach

PHP Processing session Function Summary sharing

PHP four basic sorting algorithms and two search algorithms

Related Article

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.