Search

I'm trying to plot a set of pointers on a Google map using inline Javascript.

The pointers use names and addresses in the popup windows and these strings inevitably contain single quotes and commas - both of which stop the javascript working.

Can anyone suggest how I can escape the characters?

My XML:

  <entry id="5148">
      <name handle="earls-court">Earl's Court</name>
      <address handle="st-lukes-church-redcliffe-gardens-sw10-9hf">St Luke's Church,  Redcliffe Gardens,  SW10 9HF</address>
</entry>

The existing JS output:

var locations = [
  ['<b>Earl's Court</b>Rehearsals: Tuesdays at 8.00- 9.30pm<br />Location: St Luke's Church,  Redcliffe Gardens,  SW10 9HF', 51.618109, 0.0777507999999898, 1]
];

The required JS output:

var locations = [
  ['<b>Earl\'s Court</b>Rehearsals: Tuesdays at 8.00- 9.30pm<br />Location: St Luke\'s Church\,  Redcliffe Gardens\,  SW10 9HF', 51.618109, 0.0777507999999898, 1]
];

Both blocks of code output look the same

I've edited the comment to show what Stu is trying to achieve.

When you use backslashes in code-blocks on the forum you need to write out two of them otherwise they are stripped out. Basically, you have to escape them with backslashes.

I would use a string-replace template. Replace ' with \' and , with \,

Anyone tried escaping characters for java-script using disable-output-escaping attribute in value-of tag.

high speed business broadband

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details