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,438
  • 68
  • 55
  • 126
Shadab Mehdi
  • 546
  • 8
  • 20

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,158
  • 1
  • 14
  • 19