I have the following Regex in PERL which I need to convert to PHP
if ($referrer_url =~ /\.$domain/) { }
I currently have the following in PHP to match it, but I'm not getting the same results:
if (preg_match("/\.$domain/", $referrer_url)) { }
Can anyone tell me if what I have is the same or if I'm mistaken? Thanks!
我只是猜测您的$ domain可能包含。就像mysite.com,如果是这种情况,则需要在变量上使用preg_quote :
if (preg_match("/\.".preg_quote($domain, "/")."/", $referrer_url)) { }
If $domain is a regular string you may prefer to use strpos
to Find the position of the first occurrence of a substring in a string
. This would achieve the same result as using preg_quote with the benefit of being easier to read.
if (strpos($referrer_url, ".$domain") !== false) {
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.