preg-replace-callback

How to make the function work for pair words?

那年仲夏 提交于 2019-12-25 09:50:07
问题 My function now only works with one word. For example, I have words in an associative array. And my function replaces the array key with its value in the text. And the function to keep the words in the lower case, but when you replace words it will return the incoming word register that is written on the text. Now the function can not work with pairs of words to replace pairs of words with other pairs of words. Example: // Function: function replaceKeyToValue($request, $dict){ $response =

preg_replace_callback with Spoilers into Spoilers

喜夏-厌秋 提交于 2019-12-25 06:23:31
问题 i write something like [spoiler=Spoiler Title]text inside the Spoiler[/spoiler] and use preg_replace_callback("/\[spoiler=(.*)\](.*)\[\/spoiler\]/Usi", 'BBCode_spoiler', $text); to create a real spoiler, the result with one or more spoiler is: <script type="text/javascript"> function show_0() { if(document.getElementById("0").style.display == "inline-block") document.getElementById("0").style.display = "none"; else document.getElementById("0").style.display = "inline-block"; } </script> <a

PHP: How to make variable visible in create_function()?

社会主义新天地 提交于 2019-12-20 07:12:57
问题 This code: $t = 100; $str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/", create_function( '$matches', 'return $matches[1] + $t;' ), $func); How to make $t visible from create_function() in preg_replace() function? 回答1: An anonymous function would work, while making use of the use syntax: $t = 100; $str = preg_replace_callback("/(Name[A-Z]+[0-9]*)/", function($matches) use($t) // $t will now be visible inside of the function { return $matches[1] + $t; }, $func); 回答2: You can't make the

Using preg_replace_callback with external class

浪尽此生 提交于 2019-12-19 10:33:18
问题 I have a question for you! Normally, if you call a callback function within an OOP context you have to use array(&$this, 'callback_function') That's what I figured out. But now I want to call a callback in an external class, due to having to much callback_functions. I want to give them an own class for structure reasons. I thought: "Ok, make an instance of this class and pass it instead of $this." So I tried it with array($cb, 'callback_function') and array($this->cb, 'callback_function') but

How to use preg_replace_callback?

跟風遠走 提交于 2019-12-17 08:48:23
问题 I have the following HTML statement [otsection]Wallpapers[/otsection] WALLPAPERS GO HERE [otsection]Videos[/otsection] VIDEOS GO HERE What I am trying to do is replace the [otsection] tags with an html div. The catch is I want to increment the id of the div from 1->2->3, etc.. So for example, the above statement should be translated to <div class="otsection" id="1">Wallpapers</div> WALLPAPERS GO HERE <div class="otsection" id="2">Videos</div> VIDEOS GO HERE As far as I can research, the best

How to use preg_replace_callback?

若如初见. 提交于 2019-12-17 08:48:06
问题 I have the following HTML statement [otsection]Wallpapers[/otsection] WALLPAPERS GO HERE [otsection]Videos[/otsection] VIDEOS GO HERE What I am trying to do is replace the [otsection] tags with an html div. The catch is I want to increment the id of the div from 1->2->3, etc.. So for example, the above statement should be translated to <div class="otsection" id="1">Wallpapers</div> WALLPAPERS GO HERE <div class="otsection" id="2">Videos</div> VIDEOS GO HERE As far as I can research, the best

Replace preg_replace() e modifier with preg_replace_callback

丶灬走出姿态 提交于 2019-12-16 18:31:16
问题 I'm terrible with regular expressions. I'm trying to replace this: public static function camelize($word) { return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word); } with preg_replace_callback with an anonymous function. I don't understand what the \\2 is doing. Or for that matter exactly how preg_replace_callback works. What would be the correct code for achieving this? 回答1: In a regular expression, you can "capture" parts of the matched string with (brackets) ; in this case, you

Replace preg_replace() e modifier with preg_replace_callback

北城以北 提交于 2019-12-16 18:30:26
问题 I'm terrible with regular expressions. I'm trying to replace this: public static function camelize($word) { return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word); } with preg_replace_callback with an anonymous function. I don't understand what the \\2 is doing. Or for that matter exactly how preg_replace_callback works. What would be the correct code for achieving this? 回答1: In a regular expression, you can "capture" parts of the matched string with (brackets) ; in this case, you

Replace preg_replace() e modifier with preg_replace_callback

随声附和 提交于 2019-12-16 18:30:08
问题 I'm terrible with regular expressions. I'm trying to replace this: public static function camelize($word) { return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word); } with preg_replace_callback with an anonymous function. I don't understand what the \\2 is doing. Or for that matter exactly how preg_replace_callback works. What would be the correct code for achieving this? 回答1: In a regular expression, you can "capture" parts of the matched string with (brackets) ; in this case, you

Replace preg_replace() e modifier with preg_replace_callback

北慕城南 提交于 2019-12-16 18:29:18
问题 I'm terrible with regular expressions. I'm trying to replace this: public static function camelize($word) { return preg_replace('/(^|_)([a-z])/e', 'strtoupper("\\2")', $word); } with preg_replace_callback with an anonymous function. I don't understand what the \\2 is doing. Or for that matter exactly how preg_replace_callback works. What would be the correct code for achieving this? 回答1: In a regular expression, you can "capture" parts of the matched string with (brackets) ; in this case, you