Skip to main content
added 298 characters in body
Source Link
BlitZ
  • 12.2k
  • 3
  • 52
  • 70

str_replace() supports array parameters:

// translation map:
$map = [
    '`' => '``',
    '#' => '##'
];

// what to replace:
$from = array_keys($map);

// replace by what:
$to   = array_values($map);

echo htmlentities(str_replace($from, $to, $row['column']), ENT_QUOTES);

In rare cases, that requires you to minify your code, you may try to use that:

echo htmlentities(str_replace([ '`', '#' ], [ '``', '##' ], $row['column']), ENT_QUOTES));
//                            ^             ^
//                        from what     by what

      

str_replace() supports array parameters:

// translation map:
$map = [
    '`' => '``',
    '#' => '##'
];

// what to replace:
$from = array_keys($map);

// replace by what:
$to   = array_values($map);

echo htmlentities(str_replace($from, $to, $row['column']), ENT_QUOTES);

str_replace() supports array parameters:

// translation map:
$map = [
    '`' => '``',
    '#' => '##'
];

// what to replace:
$from = array_keys($map);

// replace by what:
$to   = array_values($map);

echo htmlentities(str_replace($from, $to, $row['column']), ENT_QUOTES);

In rare cases, that requires you to minify your code, you may try to use that:

echo htmlentities(str_replace([ '`', '#' ], [ '``', '##' ], $row['column']), ENT_QUOTES));
//                            ^             ^
//                        from what     by what

      
Source Link
BlitZ
  • 12.2k
  • 3
  • 52
  • 70

str_replace() supports array parameters:

// translation map:
$map = [
    '`' => '``',
    '#' => '##'
];

// what to replace:
$from = array_keys($map);

// replace by what:
$to   = array_values($map);

echo htmlentities(str_replace($from, $to, $row['column']), ENT_QUOTES);