preg-replace-callback

Convert a function from preg_replace to preg_replace_callback()

大憨熊 提交于 2019-12-02 10:26:41
I need to convert preg_replace() to preg_replace_callback() in this function of an outdated CMS extension: // santizes a regex pattern private static function sanitize( $pattern, $m = false, $e = false ) { if( preg_match( '/^\/(.*)([^\\\\])\/(.*?)$/', $pattern, $matches ) ) { $pat = preg_replace( '/([^\\\\])?\(\?(.*\:)?(.*)\)/Ue', '\'$1(?\' . self::cleanupInternal(\'$2\') . \'$3)\'', $matches[1] . $matches[2] ); $ret = '/' . $pat . '/'; if( $m ) { $mod = ''; foreach( self::$modifiers as $val ) { if( strpos( $matches[3], $val ) !== false ) { $mod .= $val; } } if( !$e ) { $mod = str_replace( 'e'

Case insensitive preg_replace_callback

蹲街弑〆低调 提交于 2019-12-02 09:17:20
In the function below, I want to match the keyword case insensitive (should match "Blue Yoga Mats" and "blue yoga mats")... However, it currently only matches if the keyword is the same case. $mykeyword = "Blue Yoga Mats"; $post->post_content = preg_replace_callback("/\b($mykeyword)\b/","doReplace", $post->post_content); // the callback function function doReplace($matches) { static $count = 0; // switch on $count and later increment $count. switch($count++) { case 0: return '<b>'.$matches[1].'</b>'; // 1st instance, wrap in bold case 1: return '<em>'.$matches[1].'</em>'; // 2nd instance, wrap

Symfony 1.4 using deprecated functions in php 5.5

夙愿已清 提交于 2019-11-30 03:18:05
I recently upgraded PHP from version 5.3.27 to 5.5.0. Everything is working fine in my Symfony 2.3.2 project, and I can enjoy the latest PHP functionalities. Now when I am going back to my other Symfony 1.4.16 project, I get a PHP error about preg_replace being deprecated with the /e modifier. I can find no reference about this error in the forums: Has anyone had this problem before ? Is there any kind of patch that I could apply out of the box ? Is an upgrade to Symfony 1.4.20 going to fix this issue ? The error message goes like this: Deprecated: preg_replace(): The /e modifier is deprecated

Convert: “preg_replace” -> “preg_replace_callback”

雨燕双飞 提交于 2019-11-29 18:06:51
I'm trying to update my code but I'm stuck at this codeline. How do I proceed to convert this to preg_replace_callback? $buffer = preg_replace("#§([a-z0-9-_]+)\.?([a-z0-9-_]+)?#ie","\$templ->\\1(\\2)",$buffer); Here is the process of converting preg_replace (with the e modifier) to preg_replace_callback . You create a function that will act on all of the matches that it finds. Normally this is pretty simple, however with your case it is a little more complex as the function returns the value of an object. To accommodate this, you can use an anonymous function (a function without a name) and

PHP: Using special characters in bad word obfuscator

流过昼夜 提交于 2019-11-29 12:53:57
I'm using this bad word detector/obfuscator in php (to be Adsense compliant). It shows the first letter of the bad word, and replaces the remaining letters with this character: ▪ It works fine, except when I'm using words that contain special characters in Spanish, for example: ñ, á, ó, etc. This is my current code: <? function badwords_full($string, &$bad_references) { static $bad_counter; static $bad_list; static $bad_list_q; if(!isset($bad_counter)) { $bad_counter = 0; $bad_list = badwords_list(); $bad_list_q = array_map('preg_quote', $bad_list); } return preg_replace_callback('~('.implode(

Symfony 1.4 using deprecated functions in php 5.5

扶醉桌前 提交于 2019-11-29 00:23:52
问题 I recently upgraded PHP from version 5.3.27 to 5.5.0. Everything is working fine in my Symfony 2.3.2 project, and I can enjoy the latest PHP functionalities. Now when I am going back to my other Symfony 1.4.16 project, I get a PHP error about preg_replace being deprecated with the /e modifier. I can find no reference about this error in the forums: Has anyone had this problem before ? Is there any kind of patch that I could apply out of the box ? Is an upgrade to Symfony 1.4.20 going to fix

Convert: “preg_replace” -> “preg_replace_callback”

a 夏天 提交于 2019-11-28 12:07:33
问题 I'm trying to update my code but I'm stuck at this codeline. How do I proceed to convert this to preg_replace_callback? $buffer = preg_replace("#§([a-z0-9-_]+)\.?([a-z0-9-_]+)?#ie","\$templ->\\1(\\2)",$buffer); 回答1: Here is the process of converting preg_replace (with the e modifier) to preg_replace_callback . You create a function that will act on all of the matches that it finds. Normally this is pretty simple, however with your case it is a little more complex as the function returns the

PHP: Using special characters in bad word obfuscator

爷,独闯天下 提交于 2019-11-28 06:35:54
问题 I'm using this bad word detector/obfuscator in php (to be Adsense compliant). It shows the first letter of the bad word, and replaces the remaining letters with this character: ▪ It works fine, except when I'm using words that contain special characters in Spanish, for example: ñ, á, ó, etc. This is my current code: <? function badwords_full($string, &$bad_references) { static $bad_counter; static $bad_list; static $bad_list_q; if(!isset($bad_counter)) { $bad_counter = 0; $bad_list = badwords

How to convert preg_replace e to preg_replace_callback?

前提是你 提交于 2019-11-28 02:12:50
Okay, so I'm slightly confused. Here is the code I have now, but I just found out the e modifier is deprecated. How do I convert it to a preg_replace_callback() ? I still haven't figured it out. $post = preg_replace("/\[code\]([^] )\[\/code\]/e", 'code(\'$1\')', $post); If memory serves, preg_replace_callback() gives you the results of a $match from preg_match() as input, and expects the final result as output. So you'd need to write a function that returns e.g. "code('{$match[1]}')" . It can be an inline function, naturally, if php 5.3 is an option: preg_replace_callback($regex, function(

Replace preg_replace() to preg_replace_callback() [duplicate]

怎甘沉沦 提交于 2019-11-28 01:23:02
This question already has an answer here: Replace preg_replace() e modifier with preg_replace_callback 2 answers $source = preg_replace('/&#(\d+);/me', "utf8_encode(chr(\\1))", $source); The above code gives deprecated warning. Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in How can I replace preg_replace() to preg_replace_callback() ? Read the documentation here, http://www.php.net/manual/en/function.preg-replace-callback.php Here is an example of preg_replace_callback $source = preg_replace_callback('/&#(\d+);/m', function($matches){ return