0

I have PHP Script / HTML

$string1 = 'Foo';
$string2 = 'Bar';
$string3 = 'This string contains some URL';
$string4 = 'This string contains multi-line short description which contains single quotes, double quotes and some comma characters as well.';

Here is my onClick

<a class="someClass" title="someTitle" href="#" onclick="someFunction('<?php echo $string1; ?>', '<?php echo $string2; ?>', '<?php echo $string3; ?>', '<?php echo $string4; ?>')">Click Here</a>

But while receiving, I am getting all sorts of string parsing errors on someFunction()

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Shadab Mehdi
  • 604
  • 10
  • 23

1 Answers1

1

In php side use:

<?php echo addslashes($string1); ?>

And inside someFunction( string1 ) use:

string1 = string1.replace(/\\/g, '');

To get the normal value of the string;

guramidev
  • 2,228
  • 1
  • 15
  • 19