Warning: preg_replace(): Unknown modifier

Viewed 53116

I have the following error:

Warning: preg_replace(): Unknown modifier ']' in xxx.php on line 38

This is the code on line 38:

<?php echo str_replace("</ul></div>", "", preg_replace("<div[^>]*><ul[^>]*>", "", wp_nav_menu(array('theme_location' => 'nav', 'echo' => false)) )); ?>

How can I fix this problem?

3 Answers

If you would like to get an exception (MalformedPatternException), instead of warnings or using preg_last_error() - consider using T-Regx library:

<?php
try 
{
    return pattern('invalid] pattern')->match($s)->all();
}
catch (MalformedPatternException $e) 
{
    // your pattern was invalid
}
Related