PHP regular matching for strings

墨辰丷
Release: 2023-03-30 17:16:02
Original
7445 people have browsed it

This article mainly introduces PHP's regular matching of strings. Interested friends can refer to it. I hope it will be helpful to everyone.

The specific implementation method is as follows:

/** * is_external_link 检测字符串是否包含外链 * @param string $text 文字 * @param string $host 域名 * @return boolean false 有外链 true 无外链 * / 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; }
Copy after login

Summary: The above is the entire content of this article, I hope it can be helpful to everyone’s study .

Related recommendations:

How PHP implements the integration of DISCUZ users

Summary sharing of PHP processing session functions

PHP four basic sorting algorithms and two search algorithms

The above is the detailed content of PHP regular matching for strings. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!