I wanted to pull out html code Target URL and forgive with a variable
<img src="https://www.test.de/adtrack/3a10056f3.img" border="0" />
$url = https://www.test.de/adtrack/3a10056f3.html
the $url wants to echo that too in php
Just echo the whole thing with your variable added in it.
$url = 'https://www.test.de/adtrack/3a10056f3.html'
echo '<img src="https://www.test.de/adtrack/3a10056f3.img" border="0" />';
or, echo it inside your html like this:
<img src="https://www.test.de/adtrack/3a10056f3.img" border="0" />
If you do as above, remember that your file extension should be ".php" and not ".html" or else it won't work.
Related
In my code I show some images in this way:
...
<?php echo '<img src="' .$imageone. '" alt="" /> '?></a></div>
<?php echo '<img src="' .$imagetwo. '" alt="" /> '?></a></div>
...
where $imageone, $imagetwo have path from Mysql database
e.g.
$imagesone = "images/exposition/02-05-2017-11-28-00-foto 2_b.JPG";
This code is working in the same place where I have my images folder, but now I need to put the same code in a subfolder page and I'd like to use the same image.
So, I need to put dinamically "../" before my varible, something like this:
...
<?php echo '<img src="../' .$imageone. '" alt="" /> '?></a></div>
<?php echo '<img src="../' .$imagetwo. '" alt="" /> '?></a></div>
...
but it's not working.
Any suggestion?
EDIT This is my solution:
if ($images1 != ""){
$imageone = "../".$images1;
}
if ($images2 != ""){
$imagetwo = "../".$images2;
}
in this way I fixed my code and it's working!
Since you're using double quotation marks after src, you can just write down <img src="../$imageone" alt="" />
There's no need to use simple quotation marks to write the variable because the double quotation marks gets the variable number.
On this link I was learning about file_get_contents and I'd like to incorporate it into a simple if/else statement but can't seem to get it correct.
I'd like to check if the file exists and if not, display a no_image.jpg graphic.
My struggle is that the tag already has a PHP echo so it is causing the snippet to stop working. How do I format the if/else while still haveing the use the dynamic value from the echo if file_get_contents is true?
Currently I have a simple tag like this:
<img width="200" height="150" src="images/<?php echo(rawurlencode($row['MLS_NUMBER'])); ?>_1.jpg" alt="" align="left" vspace="3" hspace="3" />
Basically:
<?php
if (file_exists(...)) {
$path = ...;
} else {
$path = 'no_image.jpg';
}
?>
<img src="images/<?php echo $path; ?>" />
//add a semicolon after echo $path otherwise it won't work
Assuming you are looking for a jpg file based on $row['MLS_NUMBER']
<img width="200" height="150" src="images/
<?php
if (file_exists($row['MLS_NUMBER']) {
echo(rawurlencode($row['MLS_NUMBER'])).'_1.jpg';
} else {
echo "no_image.jpg";
}
?>" alt="" align="left" vspace="3" hspace="3" />
Pretty straight forward simple question, can you open a php code block to call image information in html? I don't think I phrased that right. Here is my code:
<img src="../inventory_images/' . <?php echo $item_number; ?> . '.jpg" width="150" height="150" border="2" />
This code is within the tags
I'm just trying to post a photo using the $item_number variable (which is also the name of the image file i.e. $item_number = T3144 and the image file is name T3144.jpg ). Also if there is a better way to accomplish this suggestions are happily accepted. Sorry to take up bandwidth with such a remedial question but for some reason I can't seem to answer this question in research. Thanks for taking the time everyone.
Your code is wrong, try:
<img src="../inventory_images/<?php echo $item_number;?>.jpg" width="150" height="150" border="2" />
with what you have it looks like the code you had would print
src="../inventory_images/' . whateveritem_numberis . '.jpg"
Yes that is perfectly fine, but make sure that this code is in a file that ends with .php or it will not get parsed by PHP. Also, you need to take out the single quotes and periods:
<img src="../inventory_images/<?php echo $item_number; ?>.jpg" width="150" height="150" border="2" />
Unless the above HTML is in an echo statement, you need to change it to this:
<img src="../inventory_images/<?php echo $item_number; ?>.jpg" width="150" height="150" border="2" />
That will in-turn look like this:
<img src="../inventory_images/T3144.jpg" width="150" height="150" border="2" />
Of course, that is going off of your example where $item_number = 'T3144';.
The single quotes and periods are used for concatenating variables inside of strings.
I have a string, an img url, in a php block called $str. And I want to set that string as the img src in an img src but its not working.
<img src="<?php $str ?>" height="50px" width="50px">
how else can i set the src to the $str string?
<img src="<?php echo $str;?>" height="50px" width="50px">
Well, I found correct answer for this problem. Nothing works well from above answers, that codes only print out source string to html page on site.
This works for me (I have my function that return source string of picture):
require_once("../../my_coded_php_functions.php");
<?php echo '<img src="' . getSourcePathOfImage() . '" />' ?>
This site(article) helped me to find and understand solution:
http://php.net/manual/en/faq.html.php
<?php echo '<img src="'.$str.'" height="50px" width="50px">' ?>
Other ways, although is not recommended. You may try :
<img src="<?=$str?>" height="50px" width="50px">
this will work, only if (in php.ini)
short_open_tag = On
Here's my code:
<embed src="/sound/lowyourchicken.mp3"
width="140" height="40" autostart="true" loop="TRUE">
</embed>
I would like the src for the .mp3 to take in to account that there are many randomly named .mp3 files in the /sound/ directory, and to choose one at random each time the page is opened. Any clues for me?
My server is PHP enabled but I'd like to keep this as simple as possible.
This should do it:
$files = glob("/path/to/directory/*.mp3");
$random = array_rand($files)
Then do this:
<embed src="<?php echo $random ?>"
width="140" height="40" autostart="true" loop="TRUE">
</embed>
array_rand returns what random index it chose, so you'll need to do this:
<embed src="<?php $files[ $random ] ?>"
Try This:
It will Work, I used original code found in answers and did some tweaking by adding array($files) in the $random = array_rand(); variable statement
You will first need to put the PHP code in the body like this
<?php
$files = glob("assets/songs/SayYesToLove/*.mp3");
$random = array_rand(array($files));
?>
next add this just outside that php code in the body
<embed src="<?php echo $files[$random]; ?>" width="140" height="40" autostart="true" loop="TRUE">
</embed>
Please Notice the echo output in the src file. This will ensure it gets outputted to your page. Also don't forget to use the ; at the end of every php variable statement as this can through some errors.