preg_replace_callback just take 5 parameter?

I write preg_replace_callback with 6 parameters like this

$aTagPattern = '/<a[^>]*(href=["']([^"']*))+[^>]*>([^<]*)</a>/';

$content3 = preg_replace_callback($aTagPattern,"next_year",$content,-1,$count,PREG_OFFSET_CAPTURE);

And the PHP will complains that :

Warning: preg_replace_callback() expects at most 5 parameters, 6 given in /data/www/km/app/webroot/t.php on line 1877

But the preg_replace_callback ‘s decalaration says it takes 6 parameters not 5:

function preg_replace_callback ($regex, callable $callback, $subject, $limit = -1, &$count = null, $flags=[]) {}

How could this error happen?

Answer

From the PHP manual:

Version 7.4.0 The flags parameter was added.

Upgrade your php version.


Ideally, you shouldn’t be using a preg_ function to modify a valid html document. You should use a legitimate dom parser.

Leave a Reply

Your email address will not be published. Required fields are marked *