Warning: preg_match_all(): Unknown modifier '4' [duplicate] - php

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
I have the following error:
Warning: preg_match_all(): Unknown modifier '4' in file.php on line 410
Code on line 410:
preg_match_all("#$replacement_pattern#is", $text, $arr);
Can someone please help me to fix this problem?

The issue is caused by the pattern having an unescaped regex delimiter that is # in your case.
At line 396, the $row['bbcode_in'] is a simple string, and all # symbols can be escaped then, so that afterwards you could use # as regex delimiters.
So, Line 396 must look like:
$replacement_pattern = str_replace('#', '\\#', trim($row['bbcode_in']));

Related

php preg_match_all returns error message "preg_match_all(): Unknown modifier 'y' -- at line 5" [duplicate]

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
When i give this regular expression for validating URL it shows error...
preg_match(): Unknown modifier '/' in C:\wamp64\www\php\Form
Validation\form.php on line 36
if(!preg_match("/%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?#|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)){
$websiteerror="Invalid URL";
Since you used forward slash / as the delimiter, you must escape it inside the regex:
if (!preg_match("/%^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?#|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)) {
$websiteerror = "Invalid URL";
}
Now the code runs for me, but I still get this warning:
PHP Warning: preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 106 in source_file.php on line 3
It seems PHP doesn't completely like the hex ranges you used in some of your character classes.

preg_match(): Unknown modifier '/' [duplicate]

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
When i give this regular expression for validating URL it shows error...
preg_match(): Unknown modifier '/' in C:\wamp64\www\php\Form
Validation\form.php on line 36
if(!preg_match("/%^(?:(?:https?|ftp)://)(?:\S+(?::\S*)?#|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)){
$websiteerror="Invalid URL";
Since you used forward slash / as the delimiter, you must escape it inside the regex:
if (!preg_match("/%^(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?#|\d{1,3}(?:\.\d{1,3}){3}|(?:(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)(?:\.(?:[a-z\d\x{00a1}-\x{ffff}]+-?)*[a-z\d\x{00a1}-\x{ffff}]+)*(?:\.[a-z\x{00a1}-\x{ffff}]{2,6}))(?::\d+)?(?:[^\s]*)?$%iu/",$website)) {
$websiteerror = "Invalid URL";
}
Now the code runs for me, but I still get this warning:
PHP Warning: preg_match(): Compilation failed: character value in \x{} or \o{} is too large at offset 106 in source_file.php on line 3
It seems PHP doesn't completely like the hex ranges you used in some of your character classes.

I have a couple preg_replace unknown modifiers warnings on a string and I don't know the regex fix [duplicate]

This question already has an answer here:
Why preg_replace throws me a "Unknown modifier" error? [duplicate]
(1 answer)
Closed 8 years ago.
I have a string that's throwing up a couple php errors.
I'm using some regex to strip <p> tags from images and iframes.
I'm also using regex to replace a <br\> with two <br\><br\>.
I'm using it on $content in wordpress.
It's throwing an error and therefore nothing is being returned in the_content();
If I remove the functions the content appears fine, though without the formatting changes.
I assume if I fix these errors the content will work fine but I don't know how to adjust the regex.
Anyway here are the errors:
[12-Aug-2014 19:46:46 UTC] PHP Warning: preg_replace(): Unknown modifier '>' in /functions.php on line 101
[12-Aug-2014 19:46:46 UTC] PHP Warning: preg_replace(): Unknown modifier 'f' in /functions.php on line 102
[12-Aug-2014 19:46:46 UTC] PHP Warning: preg_replace(): Unknown modifier '?' in /functions.php on line 133
And of course the code:
function filter_ptags($content){
$content = preg_replace('/<p>s*(<a .*>)?s*(<img .* />)s*(</a>)?s*</p>/iU', '123', $content);
return preg_replace('/<p>s*(<iframe .*>*.</iframe>)s*</p>/iU', '1', $content);
}
function strip_content($content){
$content = preg_replace(array('/(<brs*/?>s*){1,}/'), array('<br/><br/>'), $content);
}
I really need to spend some time getting a grasp on regex...
You need to escape / in a regex expression. It should be \/
It should be \s* instead of s* to match zero or more white spaces.
Change:
(<brs*/?>s*){1,}
To:
(<br\s*\/?>\s*){1,}
Here is online demo where you can validate your regex expression as well.

PHP Preg_match() Unknown Modifier Url [duplicate]

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
I got this error message:
Warning: preg_match(): Unknown modifier '/' in C:\xampp\htdocs\easyblog\wp-content\themes\easyblog\inc\widget\flickr.php on line 225
Source code in here :
// Screen name or RSS in $username?
if (!preg_match("/http://api.flickr.com/services/feeds/", $username))
$url = "http://api.flickr.com/services/feeds/photos_public.gne?id=".urlencode($user_id)."&format=".$flickrformat."&lang=en-us".$tags;
else
$url = $username."&format=".$flickrformat.$tags;
Can someone help me, please!
You need to escape the forward slashes in your expression:
"/http:\/\/api.flickr.com\/services\/feeds/"
When you use / delimiter, then you must escape all / character if used inside pattern, for avoiding this you can use another delimiter such as #
"#http://api.flickr.com/services/feeds#"
However, your pattern needs escaping:
"/http:\/\/api.flickr.com\/services\/feeds/"

PHP preg_replace error: Unknown modifier ']' [duplicate]

This question already has answers here:
Warning: preg_replace(): Unknown modifier
(3 answers)
Closed 3 years ago.
Apologies for yet another preg_replace question!
I'm getting the error:
Warning: preg_replace() [function.preg-replace]: Unknown modifier ']' in C:\xampp\htdocs\reg.php on line 6
When running the following preg_replace:
$newContent = preg_replace('<img [^>]*.gif[^>]*?>','MATCHED',$newContent);
I've run the regex through a couple of online regex builders and it seems sound. Any ideas what I'm missing here? Am I using ] incorrectly?
You need a delimiter around your expression:
$newContent = preg_replace('|<img [^>]*.gif[^>]*?>|','MATCHED',$newContent);

Categories