php preg_match multiple urls
By : Papagrape21
Date : March 29 2020, 07:55 AM
seems to work fine I know next to nothing about php so this will make someone laugh probably. code :
// [12] to match 1 or 2
// also need to escape . for match real . otherwise . will match any char
if (!preg_match("/site[12]\.net\.nz/",$host)) {
header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
if (!preg_match("/site1\.net\.nz|site2\.net\.nz/",$host)) {
header('Location: http://www.siteblah.net.nz/temp_internet_block.cfm');
}
|
Check text area for URLs with preg_match
By : Kenterky
Date : March 29 2020, 07:55 AM
I wish this helpful for you i found this code for checking a text area: , you just need to add / like code :
preg_match("/(www.[a-zA-Z0-9_-]+)\.([a-zA-Z0-9.]+)/",$textp)
|
preg_match() to check Image urls without [img] BB tags and return boolean value using PHP
By : user2120072
Date : March 29 2020, 07:55 AM
|
preg_match to check if string has specific structure
By : Pam B
Date : March 29 2020, 07:55 AM
this one helps. Assuming only the restrictions listed in your question are needed, this will validate the string: code :
$number = 3;
$regex = sprintf('/^[^:]+:(?:[^;]+;){%d}$/', $number);
if (preg_match($regex, $string)) {
echo "It matches!";
} else {
echo "It doesn't match!";
}
php > $number = 3;
php > $regex = sprintf('/^[^:]+:(?:[^;]+;){%d}$/', $number);
php > if (preg_match($regex, 'options:blue;white;yellow;')) {
php { echo "It matches!";
php { } else {
php { echo "It doesn't match!";
php { }
It matches!
php > if (preg_match($regex, 'options:blue;white;yellow;green;')) {
php { echo "It matches!";
php { } else {
php { echo "It doesn't match!";
php { }
It doesn't match!
/.../ Start and end of the pattern.
^ Start of the string.
[^:]+ At least one character that is not a ':'.
: A literal ':'.
(?:[^;]+;){N} Exactly N occurrences of:
[^;]+ At least one character that is not a ';'.
; A literal ';'.
$ End of the string.
|
Preg_match urls in css
By : user2628638
Date : March 29 2020, 07:55 AM
around this issue For your example data, one option could be to recurse the first subpattern (?1 and use a second capturing group for the url. The url will be in capturing group 2. code :
url(\(((?:[^()]+|(?1))+)\))
$re = '/url(\(((?:[^()]+|(?1))+)\))/m';
$str = 'background:url("/product/header/img1.png") and background:url("/product/header/img2.png\' and background:url(/product/header/img3.png"))';
preg_match_all($re, $str, $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if (preg_match('/^([\'"]?)[^"]+\1$/', $match[2])) {
echo trim($match[2], "'\"") . PHP_EOL;
}
}
/product/header/img1.png
|