0

I'm using a tool tip jquery plugin and it requires single quotes in the link attributes like so:

   <a href="#" class="tooltip" title="<img src='my-image.png' width='100' height='100' />

however i'm trying to save this inside a php variable like so:

$calendar.= '<div class="event-day tooltip"><a href="event.php?id='.$event['event_id'].'"title="<img src="my-image.jpg" width="500" height="400"/><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';

as you can see in the title attribute it isnt going to work because of title="

4
  • you can also put single quotes in html parkup, I don't think it matters. Commented Oct 10, 2013 at 7:45
  • \' see this. Commented Oct 10, 2013 at 7:45
  • That's not a valid element, as you never close the a tag, and also having HTML inside an attribute is not a great idea. Commented Oct 10, 2013 at 7:46
  • stackoverflow.com/questions/3626627/… Commented Oct 10, 2013 at 7:50

7 Answers 7

1

You say you need to generate this:

<a href="#" class="tooltip" title="<img src='my-image.png' width='100' height='100' />

... but this is completely invalid HTML to begin with.

I suspect you actually want to insert some arbitrary HTML such as:

 <img src='my-image.png' width='100' height='100' />

... inside a title attribute:

 <a href="#" class="tooltip" title="">Foo</a>

It's not particularly difficult:

<?php
$title = "<img src='my-image.png' width='100' height='100' />";
echo '<a href="#" class="tooltip" title="' . htmlspecialchars($title) . '">Foo</a>';
<a href="#" class="tooltip" title="&lt;img src='my-image.png' width='100' height='100' /&gt;">Foo</a>
Sign up to request clarification or add additional context in comments.

Comments

0

Use escape characters \'

$calendar.= '<div class="event-day tooltip"><a href="event.php?id='.$event['event_id'].'"title="<img src=\'my-image.jpg\' width=\'500\' height=\'400\'/><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';

1 Comment

this is what I have but it doesnt seem to work: $calendar.= '<div class="event-day"><a href="event.php?id='.$event['event_id'].'"class="tooltip" title="<img src=\''.$event['event_id'].'.jpg\' width=\'500\' height=\'400\'/><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';
0

use \

   $calendar.= '<div class="event-day tooltip"><a href="event.php?id='.$event['event_id'].'"title="<img src=\'my-image.jpg\' width=\'500\' height=\'400\'" /><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';

Comments

0

You are missing to add space before title="

<a href="event.php?id='.$event['event_id'].'" title="<img src="my-image.jpg" width="500" height="400"/><span class="hb">'.$hour.'</span> '.$event['name'].'</a>';
                                           ^^^^^^               

Problem is 2 attributes href and title are mixed in your code. you need to separate it.

Comments

0

Try saving it in a variable escaping quotes instead of using double quotes in your title attribute.

Also your markup is incorrect since you're closing an <a> and a <div> that are never opened. (changed it in example below)

$calendar.= '<div class="event-day tooltip"><a href="event.php?id='.$event['event_id'].'"title="<img src=\'my-image.jpg\' width=\'500\' height=\'400\'/><span class=\'hb\'>'.$hour.'</span> '.$event['name'].'">';

2 Comments

this is what i have but it doesnt seem to work: $calendar.= '<div class="event-day"><a href="event.php?id='.$event['event_id'].'"class="tooltip" title="<img src=\''.$event['event_id'].'.jpg\' width=\'500\' height=\'400\'/><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';
Try changing it like this (since your <a> tag syntax will otherwise be incorrect: $calendar.= '<div class="event-day"><a href="event.php?id='.$event['event_id'].'"class="tooltip" title="<img src=\''.$event['event_id'].'.jpg\' width=\'500\' height=\'400\'/>"><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';
0

Store the image tag in a variable and use it as follows:

$myImg="<img src='my-image.jpg' width='500' height='400'/>";
$calendar.= "<div class='event-day tooltip'><a href='event.php?id=$event[event_id]' title='$myImg'><span class='hb'>$hour</span>$event[name]</a></div>";

Plus, you don't need to concatenate PHP variables when using with strings.

echo "Hi $myname, how u doing?";

is better than

echo "Hi ".$myname.", how u doing?";

Comments

0

Try this:

$calendar = '<div class="event-day tooltip"><a href="event.php?id='.$event['event_id'].' "title="<img src=\'my-image.jpg\' width="500" height="400"/><span class="hb">'.$hour.'</span> '.$event['name'].'</a></div>';

Comments

Your Answer

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.