Results 1 to 4 of 4
Thread: Escape JS to build php string
Nov 9, 2011, 17:20 #1
Escape JS to build php string
I need to escape certain characters in the following line:
<a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
so that I can insert them into a php echo,
i.e. $my_string = "<a onclick="$('#product').submit(); etc...etc"
I am usually pretty decent at doing this but I am having some strange results and would really appreciate a fresh pair of eyes on it.
Silversurfer"Persistence is the path to perfection"
Nov 9, 2011, 17:28 #2
- Join Date
- Apr 2011
- no fixed address
- 0 Post(s)
- 0 Thread(s)
you might have to split the string up, escape the relevant bits and then concatenate the split bits.
But $my_string already contains a php section with an echo statement in it. Then when you echo $my_string you will be trying to echo an echo statement. Is that what you want to do ??
Nov 9, 2011, 17:35 #3
Hi thanks for your reply,
Its part of a very complex ecommerce CMS so while I don't want to echo an echo specifically I need the data from it so I guess I would have to shorten that to $button_add_to_cart.
My problem is that I am trying to take one hyperlink button (the code above) and spit it out multiple times (looping though an array to change the id each time) so I can't just write the HTML and echo what I need once, I need to include all of the HTML above in one php string. Does that make sense?
In other words, my controller file can perform the loop but I can only echo once in my view(template) so I need one string.
thanks"Persistence is the path to perfection"
Nov 10, 2011, 02:26 #4
- Join Date
- Oct 2006
- France, deep rural.
- 17 Post(s)
- 1 Thread(s)