Skip to content

Instantly share code, notes, and snippets.

@goldsky
Created June 20, 2014 05:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save goldsky/bebe23644630f39c9bc0 to your computer and use it in GitHub Desktop.
Save goldsky/bebe23644630f39c9bc0 to your computer and use it in GitHub Desktop.
Output modifier to escape HTML for javascript's value
<?php
$output = $input;
$output = str_replace('/', '\/', $output);
$output = str_replace("\n", '', $output);
$output = preg_replace("/(>+(\s)*<+)/", '><', $output);
$output = preg_replace("/\s+/", ' ', $output);
return $output;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment