Answer the question
In order to leave comments, you need to log in
How to write a regular expression in PHP to validate a URL?
Help how to write a regular expression in php. To check the URL of a page. For example, the user entered a link, it must be checked. But it is assumed that the link is always of this type mysite.com/# and then 5 characters of letters or numbers of the English alphabet. No matter how I tried to implement it, it doesn't work.
Thank you in advance for your help!
Answer the question
In order to leave comments, you need to log in
1) You can for example like this
$url = 'http://mysite.com/#something';
$base ='http://mysite.com/#';
if (preg_match('~^'.preg_quote($base).'[a-z0-9]{5}$~i', $url)) {
echo 'Valid';
} else {
echo 'Invalid';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question