escaping single quotes in php output.

jblayney
jblayney used Ask the Experts™
on
Hello,

I am generating a google map using advanced custom fields, it works great except that I have a lot of French text and they used single quotes all over the place, the single quotes are breaking my google map output..

I tried wrapping my field (   the_field('street_address')     ) in esc_html(), esc_html() and  esc_attr() with no luck..

var contentString<?php echo $post->ID; ?> = '<div id="content">'+

      '<div id="siteNotice">'+

      '</div>'+

     '<h3 id="firstHeading" class="firstHeading"><?php the_title(); ?></h3>'+

      '<div id="bodyContent">'+

      '<p><b>Address:</b> <br /><?php echo the_field('street_address'); ?>, <?php echo the_field('city'); ?><br /> ' +

      '<?php echo the_field('postal_code'); ?><br><br />' +

	  '<b><a href="<?php echo the_field('website'); ?>" target="_blank">Visit website</a></b><br />' +

       '<b><span>Distance: <?php echo get_the_distance(null, 1); ?> KM </span></b><br />' +
	   
	   '</p>'+

      '</div>'+

      '</div>';

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Hello,
Yes I did.. It didn't work. Also this is output to page, not entering into DB

Author

Commented:
i wondering if it is because it is an ACF (Advanced Custom Fields) field
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

I frequently meet this problem.
The simplest way I have found is to replace the apostroph by an acute accent
&#180;      &#xB4;      &acute;

The look is almost the same....
Consider changing that in your datafile as well as when processing it thru php

(Just for the fun: my village name has an apostroph. When buying anything online, if I leave the apostroph anything can happen during the data transfers between the different carriers )
Commented:
Hello,

I figured this out by changing ACF fucntions
I changed
 the_field
to
get_field

Author

Commented:
thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial