• Resolved gbonvehi

    (@gbonvehi)


    Hi Greg,

    Sorry to bother you again, this is just a tip actually, I saw that you replaced htmlentities with addslashes in your code, you could use json_encode to ensure all characters are compatible with JS.
    For example:
    text: '<b><?php echo addslashes(__($chart_title, 'wp_statistics')); ?></b>',
    would become
    text: <?php echo json_encode('<b>' . __($chart_title, 'wp_statistics') . '</b>') ?>,
    it will include starting and closing quotes too and escape other things like /b.

    https://www.ads-software.com/plugins/wp-statistics/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Contributor Greg Ross

    (@gregross)

    Thanks, I couldn’t find any reference as the best practice on that. I’ll take a look at json_encode().

    Thread Starter gbonvehi

    (@gbonvehi)

    You’re welcome Greg, I think it’s the easiest way to ensure the output is valid Javascript. I’ll mark this as resolved since it was just a suggestion.

    Cheers,
    Guillermo

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Use json_encode instead of add_slashes in PHP->JS code’ is closed to new replies.