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