0
votes

I'm terrible with regular expressions. I'm trying to replace this:

$cleaned[0]['body'] = preg_replace('~&#x([0-9a-f]+);~ei', 'chr(hexdec("\\1"))', $cleaned[0]['body']);
$cleaned[0]['body'] = preg_replace('~&#([0-9]+);~e', 'chr("\\1")', $cleaned[0]['body']);

with preg_replace_callback I try this:

$cleaned[0]['body'] = preg_replace_callback('~&#x([0-9a-f]+);~e', create_function ('$matches', 'return chr(hexdec($matches[1]));'), $cleaned[0]['body']);
$cleaned[0]['body'] = preg_replace_callback('~&#([0-9]+);~', create_function ('$matches', 'return chr($matches[1]);'), $cleaned[0]['body']);
1
What's your question? - Andrew Arnold

1 Answers

0
votes

create_function() is often times disabled for security reasons since it executes an eval() call. With preg_replace_callback(), you should just be able to define your callable function as a parameter:

$cleaned[0]['body'] = preg_replace_callback(
  '~&#([0-9]+);~',
  function($matches) {
    return chr($matches[1]);
  },
  $cleaned[0]['body']
);