Skip to content

Instantly share code, notes, and snippets.

@isotrope
Created April 16, 2020 18:46
Show Gist options
  • Save isotrope/7f452b2ec0ffbb1b3189c1dab5c2dbb8 to your computer and use it in GitHub Desktop.
Save isotrope/7f452b2ec0ffbb1b3189c1dab5c2dbb8 to your computer and use it in GitHub Desktop.
<?php
$my_var = 'Something
on multiple
lines';
$cleaned_var = str_replace( [ "\r", "\n", chr( 10 ), chr( 13 ) ], '', $my_var );
// comme Oleg dit, juste au cas où tu te bats contre des quotes
$cleaned_var = str_replace('"', '&quot;', $cleaned_var);
?>
<script>
var jsVar = "<?php echo $cleaned_var; ?>";
console.log( jsVar );
</script>
<?php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment