smile Posted September 4, 2017 Share Posted September 4, 2017 This code works in PHP file OK. <a href="http://www.example.com" target="_blank"><img src="http://www.example.com/demo.png" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src='http://www.example.com/demo2.png'/> But if I place it inside PHP echo like this <?php //SET THE TIME ZONE date_default_timezone_set('Europe/Vilnius'); //BEGIN $today = strtotime(date("Y-m-d")); $expireDate = strtotime("2017-12-31"); if ($today <= $expireDate) { //ACTIVE echo '<a href="http://www.example.com" target="_blank"><img src="http://www.example.com/demo.png" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src='http://www.example.com/demo2.png'/>'; } else { //EXPIRED echo ''; } ?> I get the error Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' Somebody told me that "I need three types of quotes" Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 4, 2017 Share Posted September 4, 2017 You cannot open your echo with single quotes and use single quotes within the string without escaping them. Since you don't have any variables in your string, use double quotes for the image source. Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 use double quotes for the image source I tried that first thing. I get no PHP error but the script does not work then. This does not work, does not get the second image loaded <a href="http://www.example.com" target="_blank"><img src="http://www.example.com/demo.png" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src="http://www.example.com/demo2.png"/> Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2017 Share Posted September 5, 2017 Escaping in PHP: 'data-tipso-content="' "data-tipso-content='"Escaping in HTML (the "third tier"): 'data-tipso-content="' 'data-tipso-content="' "data-tipso-content='" "data-tipso-content='" Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 (edited) I tried pasting you code the code above and still get the Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' You did not translate the whole code string. I use the https://github.com/object505/tipso I should have mentioned this above. Edited September 5, 2017 by smile Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2017 Share Posted September 5, 2017 I don't know what you did but the examples I posted are syntactically correct for PHP (though they are missing the same closing quote on the attribute as yours was). Look at how they work and incorporate whichever one into your code. Don't just copy and paste. Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 For some unknown reason the code is painted wrong in dreamweaver, and it does not work also. Any one knows why that is? See attached screenshot. Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 5, 2017 Share Posted September 5, 2017 You don't see the unescaped quote right before date-tipso? Quote Link to comment Share on other sites More sharing options...
requinix Posted September 5, 2017 Share Posted September 5, 2017 And you're missing a closing ". Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 I'm having hard time to understand what is needed as my main language is not english, and I'm not a programmer. I fixed the code like this. See attached image. Now error is: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ',' or ';' in Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 5, 2017 Share Posted September 5, 2017 Using your original posted 'bad' line, just add the \ where the single quotes are inside your entire string. Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 I posted a online test http://jsbin.com/cesuwuqomo/edit?html,output help is appreciated. Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 Using your original posted 'bad' line, just add the \ where the single quotes are inside your entire string. Tried it no images appear, no errors. Quote Link to comment Share on other sites More sharing options...
Solution Sepodati Posted September 5, 2017 Solution Share Posted September 5, 2017 (edited) https://3v4l.org/VJoGS echo '<a href="http://www.example.com" target="_blank"><img src="http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src=\'http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg\'/>">'; Edited September 5, 2017 by Sepodati Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 https://3v4l.org/VJoGS echo '<a href="http://www.example.com" target="_blank"><img src="http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src=\'http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg\'/>">'; Thank you, works perfect now. If only I could understand why I see some places changed Instead of png\'"/>'; you changed to png\'/>">'; Quote Link to comment Share on other sites More sharing options...
smile Posted September 5, 2017 Author Share Posted September 5, 2017 In case the link goes down here is the code echo '<a href="http://www.example.com" target="_blank"><img src="http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg" class="img-tipso" data-tipso-title="Tooltip title" data-tipso-content="<img src=\'http://www.petmd.com/sites/all/modules/breedopedia/images/thumbnails/cat/tn-sokoke-forest-cat.jpg\'/>">'; Quote Link to comment Share on other sites More sharing options...
Sepodati Posted September 6, 2017 Share Posted September 6, 2017 Thank you, works perfect now. If only I could understand why I see some places changed If you ignore PHP for a second, and shorten things up, this is what you want: <a href="e.com"><img src="cat.jpg" class="img-tipso" data-tipso-title="title" data-tipso-content="<img src='a.jpg'/>"> The two > symbols at the end each close one of the <img> tags. That's why you need two, one inside the double quotes and one to close the actual <img src="cat.jpg">. Now to take that into PHP, as mentioned before, you just add escape characters before the single quotes if it's enclosed by single quotes. echo '<a href="http://www.example.com"><img src="cat.jpg" class="img-tipso" data-tipso-title="title" data-tipso-content="<img src=\'a.jpg\'/>">'; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.