PHP img src (simple) [closed] - php

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I am trying to add an image file to my PHP so when I echo, the picture will appear alongside the message. However I am getting a syntax error on line 3. Any help would be appreciated.
<?php
echo "President has been killed";
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>
?>

<?php
echo 'President has been killed
<img src="D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;" /> ';
?>
Note the change in quotes -- single and double -- and placement of the semi-colon.
or
<?php
echo "President has been killed";
?>
<img src="D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;" />
Move the image outside the php. Using this depends on overall markup though.
The semi-colon ends, or stops the echo statement.

Of course there's an syntax error. You are trying to output HTML inside PHP block:
Change your code to:
<?php
echo "President has been killed";
?>
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>

<?php
echo "President has been killed";
<IMG SRC = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png;"/>
?>
firstly you don't need the entire location, place the image in the folder in your root called images then place the image in there.
<?php
echo '<p>President has been killed<p><img src = "D:/User Data\Documents/Sheridan/Summer Year 3/Enterprise Java Development/Projects/PhpAssignment/skull.png"/>';
?>

Related

PHP echo img src [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I got something like this: print '<img src="'.$rlink.'">';
it shows me right link, but image doesn't appear. When I go to browser console, I get this error: http://somesite.com/somesite.com/thisimage.jpg
I tried <img src="<? php echo $rlink; ?>"/>
It is not working. I was looking around forums but didn't found a solution. Thank you for any help!
<img src="<? php echo $rlink; ?>"/>
needs to be:
<img src="<?php echo $rlink ?>">
it might not solve the problem because i dont kno what the value of the variable is. It might be wrong.
I'm guessing your variable $rlink contains somesite.com/thisimage.jpg. Since it doesn't have a protocol at the beginning, the browser thinks it's a relative path, thus trying to go to somesite.com folder, which doesn't exist. You can either put http:// at the beginning of the src, or remove domain so it's treated like the relative path it is as of now

What is wrong with this code PHP [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have this code :
<div class="gigel"><?php
// In case there is opening and closing shortcode.
echo do_shortcode('[woocs show_flags=1 width='300px' flag_position='right']');
?></div>
This is shortcode:
[woocs show_flags=1 width='300px' flag_position='right']
This is the error:
Parse error: syntax error, unexpected '300' (T_LNUMBER) in /home/dacproie/public_html/test2/wp/wp-content/themes/mix/header.php on line 189
How can I solve this problem?
Thanks in advance!
just change below code with
<div class="gigel"><?php
// In case there is opening and closing shortcode.
echo do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?></div>
i hope this is working for you.
please, try to clean your code
<?php
$forHtml = do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?>
<!-- separate your layers -->
<div class="gigel"><?php
<?php print ("%s", $forHtml); ?>
?></div>
Always try to use double quotes when you have to use do_shortcode() function.
So use of double quotes instead of single quotes fix your problem and you need to modify it as like :
<div class="gigel">
<?php
echo do_shortcode("[woocs show_flags=1 width='300px' flag_position='right']");
?>
</div>

php - inline font style for print statement? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
I know its possible to apply inline styles to echo statements but can this be done with print statements as well?
In my pagination I have links to previous and next records using the greater and less than symbols <> and a running count of the current record against the total number of records. e.g.
<
1/2
or
>
2/2
I have styled them in css but want to decrease the size of the count only. If I make changes to the css the font size for the previous and next links and count all change, I only want to target the count.
<div class="nextcard"><?php if($nextlink != ""){ print ($nextlink."<br/>".$next."/".$count); } ?></div>
I have tried :
<div class="nextcard"><?php if($nextlink != ""){ print 'style=font:50px' ($nextlink."<br/>".$next."/".$count); } ?></div>
But get syntax errors.
One approach would be to add a class rather than inline styles. However, you have forgotten to append the string correctly.
Here is what I would personally do: (Note I replaced print with echo, TBH, there would be no different)
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span class="mark">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>
If you still want to style it inline, you should simply do:
<div class="nextcard">
<?php
if($nextlink != "")
echo '<span style="font-size:50px;">'.($nextlink."<br/>".$next."/".$count).'</span>';
?>
</div>

displaying an image from a php variable source [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to display an image on my website using html.
My problem is that the name of the image is saved in a php variable, so I've been trying to do the following:
<img src = <?php echo $fileName;?> >
Where &fileName is obviously the name of the file. If I simply echo this variable, it is exactly the correct file path for the operation, but the image is not displayed. Instead, on my website there's a little icon, which has nothing to do with my image. If I change it to this:
<img src = <?php $fileName;?> >
nothing at all is displayed.
I'd be grateful for any help.
You are missing the quotes:
try this:
<img src="<?php echo $fileName;?>">
Try this:
<img src="<?php echo $fileName; ?>" />
And also check what r u getting in echo $fileName; as there us need full path of image to dispay.
This is because of $fileName may have the /(slashes) which are breaking the images tag in the middle.
Instead of setting the name of the image, set its path or the full URL.
And add quotes for the src property.
Or you try Embedded code.....
<?php
echo "<img src='$filepath'/>";
//filepath is variable which contains path to the image file
?>

Browser changing the markup and breaking my CSS [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 years ago.
Improve this question
I have in a foreach loop:
echo "<span style=\"" . myCss($value) . "\">lol</span>";
Which turns into (in source):
<span style="">lol</span>color: #999999;background-color: transparent;font-weight:normal;text-decoration: none;<span style="">...
Why? how to prevent the browser? Same for Chrome and Firefox. Note there is a reason for it being in-line, an I want to avoid doing it via javascript.
Try this
echo "<span style='" . myCss($value) . "'>lol</span>";
How about a little separation of PHP and HTML:
<span style="<?php echo myCss($value); ?>">lol</span>
Notice I encapsulate the PHP within the quotes, rather than echo the entire line. In a foreach loop it would look something like:
<?php
foreach($array as $key => $value){
?>
<span style="<?php echo myCss($value); ?>">lol</span>
<?php
}
?>
This separation of PHP and HTML has been the standard practice everywhere that I have worked, and I personally find it to be much more transparent.
Without seeing your function and the values of the variables, I an only assume that there are characters in the echoed result that mess up the html. You should always use htmlspecialschars() when you output to html:
echo "<span style=\"" . htmlspecialschars(myCss($value)) . "\">lol</span>";
Although you would probably use it in your function.

Categories