Echo a txt file in data-caption - php

I am trying to echo in php the image description in the data-caption of the clearing image gallery of Foundation3 but it is not working. Here is my code:
<li class="clearing-feature">
<a href="administration/galleri/kcfinder/upload/images/Galleri1/1.jpg">
<img data-caption="<?php echo $myDataBild1 ?>;" src="kcfinder/upload/images/Galleri1/1.jpg"></a>
</li>
This is not working. The image gallery is still working correctly but the caption in this picture is not showing. How can I correct this?
NOTE: The php $myDataBild1 is a txt file with text inserted via CKEditor and it is working just fine. Let me know if you need the code and the variable is shown if I echo it anywhere else.

Misplaced comma - also try by using addslashes.
<img data-caption="<?php echo addslashes($myDataBild1); ?>" src="kcfinder/upload/images/Galleri1/1.jpg"></a>

Related

Trying to echo an image in Php, cant find src

i just started learning Php, right now im trying to convert a HTML page to a Wordpress Theme. I have trouble trying to display images...
In my HTML page i have imgs like:
<img class="mainlogoclean" src="images/akbarlogoclean.png"/>
When i tried to change it with php my page just stop working:
<img class="mainlogoclean" src="<?php echo /images/akbarlogoclean.png ?>"/>
You will have to echo a string for it to work properly.
i.e. have /images/akbarlogoclean.png inside single/double quotes.
You can learn more about how echo works Here
The code could be written in following ways
<img class="mainlogoclean" src="<?php echo "/images/akbarlogoclean.png" ?>"/>
Or you could also try the shorthand version of using echo
<img class="mainlogoclean" src="<?="/images/akbarlogoclean.png" ?>"/>
Both of these give the following output
<img class="mainlogoclean" src="/images/akbarlogoclean.png"/>

Joomla 3.7.1 - Adding Links and title tags to article intro images

Hi guys wondering how I can manually add a link from Joomla intro article images to their corresponding article and also add a title tag to the link.
Ideally the way I want to do this is to for example wrap an achor tag around the image reference in the blog-item.php file (also want to achieve this for generic articles). And then within the anchor tag capture the related image alt tag and populate the title tag with that value.
Below is where I'm at. It's not currently working, not sure why as it should be pretty straight forward. I'm not a php developer, wondering what i'm missing.
Also already cleared both browser and joomla caches after my changes.
Any help would be appreciated, cheers guys
<a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($this->item->slug, $this->item->catid)); ?>" title="<?php echo htmlspecialchars($images->image_intro_alt); ?>">
<img
src="<?php echo htmlspecialchars($images->image_intro); ?>"
alt="<?php echo htmlspecialchars($images->image_intro_alt); ?>"/>
</a>
To make your code work, add just before your code.
<?php $images = json_decode($this->item->images); ?>
and your code will start working.
Already tested and it worked.

php image link in table code

I have this code in my php dynamic table
<?php echo'<img src="../images/a-camera-icon.png">'.$row_rsInventory['PHOTO'].''; ?>
When the code runs it displays the link as an image and the text as a hyperlink in the PHOTO field. What do I need to change so that it just shows the link as an image in the PHOTO field. I appreciate any help on this.
Just remove the text you have for anchor .$row_rsInventory['PHOTO']. this way
<?php echo'<a href="http://'.$row_rsInventory['PHOTO'].'">
<img src="../images/a-camera-icon.png">
</a>'; ?>
Remove the anchor text .$row_rsInventory['PHOTO'] Use either of the code below
<img src="../images/a-camera-icon.png">
<?php echo'<img src="../images/a-camera-icon.png">'; ?>

Display QR Code inside colorbox?

I've been able to put some code together and get a QR code to display on my site. Now I'm attempting to get the QR Code to open a larger version inside colorbox. This is the code I've got so far:
<a href="<?php echo $????; ?>" title="<?php echo $heading_title; ?>"
class="colorbox" rel="colorbox">
<img src="http://chart.apis.google.com/chart?chs=250x250&cht=qr&chld=L&chl=
<?php $url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; echo $url; ?>"
alt="Product QR Code" width="80" height="80" style="float: right" /></a>
All the code for colorbox is on this page already as I have products that use this very function. The original code said echo $popup but when I use that it shows me the main product image so that's no good. What I can't figure out is what to do with echo in the href section so it calls the image again in the pop-up box but in a larger size?
I've tried using the same url as with the img src but it only returns garbage characters in the pop-up box and doesn't know to turn it into an image instead.
Thanks for your time!
When you assign colorbox, set the photo property to true. Example:
$('a.example').colorbox({photo:true});
Colorbox normally uses a regex to determine if a link is pointing to an image or not, but the URL you are using isn't going to pass that regex.

img src won't work with php variables

<a href="'.$productLink.'" alt="'.$productName.'">
<img src="'.$productImg1URL.'" alt="'.$productName.' '.$productType.' ">
</a>
Hello the img src is actually in a different directory /images
I know this is probably super easy but Ive spent an hour on it and nothing. The page works but doesn't show the directory. Please help the rookie. I took out the < in front of the a href and img src couldn't make the page display
There are two ways of doing this:
Firstly, outside of a code block:
<?php
// code here
?>
<a href="<?= $productLink ?>" alt="<?= $productName ?>">
<!-- or -->
<img src="<?echo $productImgURL; ?> alt="<?php echo $productName . ' ' . $productType ?>">
</a>
The first form is called the short open tag and has to be enabled in your php.ini which it almost always is.
Or if you're doing this inside a code block:
<?php
echo <<<END
<a href="$productLink" alt="$productName">
<img src="$productImgLURL" alt="$productName $productType">
</a>
END
The <<<END is a heredoc and I usually prefer it to using a big string within double quotes, which requires escaping contained double quotes.
Job #1 when you have a problem with code that is generating HTML, is look at the output source and compare it with what you expect. I've had problems like this before and they usually vanished when I stopped thinking about the PHP code, and looked at the actual output.
What is the content of $productImg1URL - and if the images that it's referencing are in the URL starting /images/ - does that start $productImg1URL. If it's just the name of an image, but without the path - you have to put that into place.

Categories