1

I haven't coded with PHP in a while and cannot remember how to do this..

I'm using a jquery plugin that requires some rel parameters to be set.

 $imgtag = '<a href="'.carturl($img->id,'images').'/'.$img->filename.'" class = "zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150">
<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' /></a>';

Now I need to add , position: "inside" to the rel bit, however, every time I do it, it outputs in HTML as quotes all over the place. The plugin must retail the quotes around the word "inside" to work, however, I need to use these quotes within the "rel=" quotes.

How do I go about this?

HTML Output should look like this:

 <a style="position: relative; display: block;" href="http://www.URL.com/theimage.jpg" class="cloud-zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:"inside"">
<img style="display: block;" src="http://www.URL.com/theimage.jpg" alt="product-picture" height="450" width="360"></a>

Thanks!

Janis Veinbergs
7,0166 gold badges52 silver badges78 bronze badges
asked Oct 3, 2011 at 9:58
4
  • are you sure there should be quotes in position: "inside" ? can't it be just position:inside ? Commented Oct 3, 2011 at 10:00
  • @itsmeee: it has to be with quotes :( won't work without Commented Oct 3, 2011 at 10:01
  • Its actually a html issue, not php :) PHP just generates whatever html you say him to generate, so i fixed the title to be more descriptive. Commented Oct 3, 2011 at 10:03
  • rel=what?!: The rel attribute has a defined purpose and that purpose is not "Store arbitrary data for JavaScript to read" (which is what data-* is for). Commented Oct 3, 2011 at 10:21

3 Answers 3

2

use single quote

rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:'inside'"

or reverse

rel='adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:"inside"'
answered Oct 3, 2011 at 10:00
Sign up to request clarification or add additional context in comments.

2 Comments

@MartinH23 Ahh, its all inside php echo statement? Ohwell, do it like rel="..., position:\'inside\'". You have to escape special characters
Thanks Janis, all sorted as per above.
0

Try with:

 $imgtag = '<a href="'.carturl($img->id,'images').'/'.$img->filename.'" class = "zoom" id="zoom1" rel="adjustX: 10, adjustY:-4, zoomWidth:150, zoomHeight:150, position:\'inside\' ">
<img src="'.$src.'"'.$titleattr.' alt="'.$alt.'" width="'.$width_a.'" height="'.$height_a.'" '.$classes.' /></a>';
answered Oct 3, 2011 at 10:04

1 Comment

PERFECT!! Thank you so much. I'll accept this answer in 5 mins ;)
-1

You can escape quotes using the following syntax:

\"your stuff\"

This will render wrapped in ", assuming you have also the outer quotes round the rel element

answered Oct 3, 2011 at 10:00

4 Comments

Tried this earlier.. outputs as: position:\" inside\""="">
possibly because your string is enclosed with single quotes, start it with " and the inside use \" to represent the quotes so an example would be $var = "<img src=\"aURL\"/>";
Nope, you can’t escape characters by preceding them with a backslash in HTML. You might be thinking of JavaScript or CSS.
I'm thinking of PHP as per the original post where you can happily write $somit = "text \"" . $var . "\" more text"; with the \" replacing ' if you so choose

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.