0

I need a little help. Because preg_replace is deprecated, I have to convert all my preg_replace to preg_replace_callback when i tried to change it its always showing some error.

i have tried

Change:

$importedOptions = preg_replace('!s:(\d+):"(.*?)";!e', "'s:'.strlen('$2').':\"$2\";'", $importedOptions);

To:

$importedOptions = preg_replace_callback(
    '!s:(\d+):"(.*?)";!e',
    function() { return "'s:'.strlen('$2').':\"$2\";'"; },
    $importedOptions
);

i have tried other approaches to but did not success please help me in this

Thanks

u_mulder
  • 54,101
  • 5
  • 48
  • 64
Deepak Goyal
  • 1,186
  • 2
  • 13
  • 26
  • I think the code should be something like this function($importedOptions) { return "'s:'.strlen('$2').':\"$2\";'";} and then no need for $importedOptions at the end – Dhaval Chheda Nov 13 '17 at 03:29
  • when was `preg_replace` deprecated, I think you mean the `e` flag was... – ArtisticPhoenix Nov 13 '17 at 03:34
  • i don't know but if you can please correct the above code than its very helpful for me – Deepak Goyal Nov 13 '17 at 03:34
  • is this serialized data you are trying to match looks like it. – ArtisticPhoenix Nov 13 '17 at 03:36
  • Yes this is serialized data and when i try to unsersalized it than its showing some error about code 6 and than i found this solution but now facing this function problem – Deepak Goyal Nov 13 '17 at 03:37
  • well first off you need to remove the `e` flag as I said which is the part that is deprecated / or removed, `'!s:(\d+):"(.*?)";!e'` the delimiter in this Regx being the `!` oddly. so `'!s:(\d+):"(.*?)";!'` – ArtisticPhoenix Nov 13 '17 at 03:48
  • i have tried it also but preg_replace_callback still shows error can you please change and add complete code as answer so if that works than i make it as approve answer thanks – Deepak Goyal Nov 13 '17 at 03:50
  • possibly if I knew what the input was, without it I would be just guessing. – ArtisticPhoenix Nov 13 '17 at 04:25

0 Answers0