preg-replace-callback Questions

4

Solved

I would like to know if there is a simple way to use the matched pattern in a preg_replace as an index for the replacement value array. e.g. preg_replace("/\{[a-z_]*\}/i", "{$data_ar...
Randolphrandom asked 26/4, 2013 at 13:37

3

Solved

How can I keep track of the current match’s offset from the start of the string in the callback of preg_replace_callback? For example, in this code, I’d like to point to the location of the match t...
Poser asked 13/12, 2011 at 3:43

2

Solved

I'm trying to replace {{key}} items in my $text with values from a passed array. but when I tried adding the print_r to see what was going on I got a Undefined variable: kvPairs error. How can I ac...
Exhalant asked 8/5, 2013 at 16:47

3

Solved

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_repla...
Tennilletennis asked 16/3, 2013 at 20:13

1

In order to print_r a collapsable tree, I'm currently using his code which uses preg_replace() and the /e modifier, which is depreciated in PHP7: <?php function print_r_tree($data) { // captur...

1

Solved

Can somebody help me with this error I'm getting? Warning: preg_replace(): The /e modifier is no longer supported, use preg_replace_callback instead My original code: $match[1] = preg_...
Votaw asked 18/3, 2018 at 13:3

1

Solved

I'm working on this old code, and ran across this - which fails: preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $sObject); It tells me that preg_replace e modifier is deprec...
Atrophy asked 8/2, 2016 at 21:24

6

Solved

I'm trying to support two versions of some PHP code in one file using version_compare, but I still get an error. Code: if (version_compare(PHP_VERSION, '5.3.0') >= 0) { $alias = preg_replace_...
Cotopaxi asked 28/2, 2015 at 22:52

7

Solved

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 ...
Chemesh asked 6/8, 2013 at 10:14

2

Solved

$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_...
Arrant asked 6/5, 2014 at 15:7

2

Solved

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...
Celka asked 24/6, 2012 at 3:46

1

Solved

$result = preg_replace( "/\{([<>])([a-zA-Z0-9_]*)(\?{0,1})([a-zA-Z0-9_]*)\}(.*)\{\\1\/\\2\}/iseU", "CallFunction('\\1','\\2','\\3','\\4','\\5')", $result ); The above code gives a...
Trespass asked 8/10, 2013 at 10:27

1

Solved

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. $p...
Moriyama asked 3/5, 2013 at 20:55

3

Solved

mmmh guys, i really hope my english is good enaught to explain what i need. Lets take this example (that is just an example!) of code: class Something(){ public function Lower($string){ return ...

2

Solved

I have few substitutions to apply on my $subject but I don't want to allow the output from old substitutions #(1 .. i-1) to be a match for the current substitution #i. $subject1 = preg_replace($pa...
Addams asked 3/7, 2011 at 20:28
1

© 2022 - 2024 — McMap. All rights reserved.