How To Correct This Code Php Syntax Error - php

This line of code is perfect for placing the image before the post's title
$title = ‘<img class=”icon_title” src=”‘. $img_source .'” />’ . $title;
But we want to place the image after the post's title. I think my code below is right
$title = $title . ‘ <img class=”icon_title” src=”‘. $img_source .'” />’;
But I am getting this error as shown in the screen shot:
Please can anyone help me to find the solution

It's happending due to your quote problem and you have not wrapped class attribute inside a string. Please follow the below code. It will help you. Convert to your keyboard to standard mode(US) and then type.
$title = $title.'<img class="icon-title" src="'.$img_source.'">';

Your " and ' were not correct type - perhaps you were editing in a word document/application. Consider writing code in applications designed for code to prevent this?
Below is the same line of code with the correct type of ' and ".
$title = $title . '<img class="icon_title" src="'. $img_source .'"/>';

Related

cant print images (.svg) of folder using matrix

just print the square but not the image, dont know what is wrong, doesnt throw mistake.
Thanks
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
Nothing wrong in your code. Check if you have correct svg image or not at particular location. (inspect using chrome developer tool)
Check using Object tag or if your browser support or not. https://www.w3schools.com/html/html5_svg.asp
I would recommend to not mix strings with code vars. Always do proper concatenation:
$str = '<img src="/img/' . $numero[$i] . '.svg"';
$str .= ' alt="' . $numero[$i] . '"';
$str .= ' title="' . $numero[$i] . '"';
$str .= ' width="140" height="140">'. "\n";
echo $str;
your code seem right, try checking if the svg image is in the correct image path you placed
i tested with this and is working well
<?php
$numero = array('imagename', 'image alt', 'title');
echo "<img src=\"Images/$numero[0].svg\" alt=\"$numero[1]\" title=\"$numero[2]\" width=\"140\" height=\"140\">\n";
?>
thank you all, I discovered that it happened
I was missing a bar in front of the img
echo "<img src=\"/img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
instead of
echo "<img src=\"img/$numero[$i].svg\" alt=\"$numero[$i]\" title=\"$numero[$i]\" width=\"140\" height=\"140\">\n";
I do not see any sense

Show table data on different page

I have a website where users can write posts, however im haveing trouble echoing the post along with its title.
Heres My Code:
Post.inc.php:
echo '<input type="button" value="Read More"
onclick="window.location=\'read_more.php?start=' .
urlencode($row['post']) . ' \';" />';
echo "</p>";
Read_more.php:
<?php
date_default_timezone_set('America/New_York');
include 'post.inc.php';
?>
<?php
$start = (!empty($_GET['start']) ? $_GET['start'] : false);
echo '<p>. $title .<br> ' . $start . '<p>';
?>
Only the post is being echoed and not the title. How would I go about fixing this problem?
-Thanks in advance
As Chris said, this is very vulnerable to XSS attacks, you need to sanitize the $_GET['start'] value before echoing it. Also, passing the entire post in the url is not a great idea. If you are storing the post in a database you are better off sending an ID value of some sort through the URL, validating/sanitizing it and retrieving the post directly from the database to be displayed.
I cannot see where you have given $title a value. It is not defined in any of the code you have provided. This means it cannot display anything when echoed.
Also, the structure of your echo is incorrect.
echo '<p>'. $title .'<br>'. $start .'</p>';
is what you are looking for here. notice the single quotes are closed before $title and re-opened before the break tag.
variable will not be expanded when it occur in single quoted strings.You can find this notice in PHP Manual
so,
echo '<p>. $title .<br> ' . $start . '<p>'
should be modified to
echo '<p>'. $title .'<br>'. $start .'</p>';
or use double quoted instead,
"<p>{$title}<br>{$start}</p>"
As Matt said, echoing the $_GET['start'] directly will make your site be vulnerable,which can result in attacks like phishing.
In a general way, there are some operations like filter,type check to sanitize the value gained from frontend. The PHP Manual provides a lot of function to do this,intval(),PCRE,mysqli_escape_string(),array_filter(),htmlspecialchars()...
IMHO,you should use a SQL server like MySQL,SQLite,or others to storage the data from frontend which can help your site work better.

echo background image with a value

I echo out an image like that:
$newString = $thumbPre.'profilemain'.$thumbPost;
echo "<img src='http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error'>";
Now i want the image as a background-image, i tried it like that, but it doesn´t work:
echo '<div style="background-image:url('http://render-api-us.worldofwarcraft.com/static-render/us/" . $newString. "' alt='error');"></div>';
you need to use backslashes for nested apostrophes
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\' alt=\'error\');></div>';
Firstly, remove alt='error' because background-image does not have an alt parameter, img does (you probably thought you could use that from your original code). In trying to use that, your background will not show up.
And your background won't show unless you have content inside that div. I've added Content as an example.
echo '<div style="background-image:url(\'http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.'\');">Content</div>';
You either have to escape the encapsulating quotes, or remove them altogether.
echo '<div style="background-image:url(http://render-api-us.worldofwarcraft.com/static-render/us/' . $newString.');">Content</div>';
Error reporting would have also thrown you a parse error such as:
Parse error: syntax error, unexpected '' alt='' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ';'
http://php.net/manual/en/function.error-reporting.php
This is going to look super confusing but you need to 1, escape the quotes and 2, concatenate your path within that,
let me give you an example. I misread a bit of the question but this will serve you well moving forward especially for cleanliness sake
here is an example:
$imagePath ='PATH TO IMAGE HERE';
echo '<div style="background-image:url(\'' .$imagePath. '\')" >STUFF HERE </div>';

How to correctly write <img src> in php without escaping to HTML

I am having trouble with my PHP code. I've been changing everything for 6 hours and I still get Parse errors no matter what I do. This is the code:
$slider3 = '<img src="'templates/' . $this->template . '/images/slider/slider3.jpg'">' . '" alt="' . $sitename . '" />';
The only way I can figure to not get it to throw an error is by writing it this way:
$slider3 = '<img src="templates/" . $this->template . "/images/slider/slider3.jpg" . "/>"';
but I don't think that's right.
I want $slider3 = "templates/MYTEMPLATE/images/slider/slider3.jpg" then later I will echo $slider3;
I get so confused with all the single and double quotation marks. I think the first one is right - I look at it and study it and it looks right to me. But it throws a parse error.
$slider3 = '<img src="templates/'.$this->template.'/images/slider/slider3.jpg"/>';
should work.
Explanation:
'<img src="templates/'
is a single-quoted string, which happens to contain a double-quote (which is needed for the html src attribute, or any other html attribute value really)
.
(dot) is the string concatenation operator. It concatenates ("glues") the first string together with...
$this->template
which is presumably a string containing the name of the template (not clear from your code example). Note that if $this->template comes from user input, or an otherwise unvalidated source, it could be used for cross-site scripting, eg. if it contains "><script>alert("XSS!")<script>, javascript is executed in the browser!
.
another concatenation with...
'/images/slider/slider3.jpg"/>'
which is another single-quoted string which happens to contain a double-quote, ending the src attribute value.
Try this:
$slider3 = '<img src="templates/"' . $this->template . '"/images/slider/slider3.jpg"/>';
$template = "MYTEMPLATE";
$slider3 = '<img src="templates/'.$template.'/images/slider/slider3.jpg"/>';
echo $slider3;
Will echo - >
<img src="templates/MYTEMPLATE/images/slider/slider3.jpg"/>
Just write:
<?php
$templates = "var";
echo "<img src='templates/${templates}/images/slider/slider3.jpg'/>";
it will result in
<img src='templates/var/images/slider/slider3.jpg'/>

Apparent PHP Syntax Error

Basically, I've been trying to make a simple Wordpress widget that displays a QR code with the URL of the current page. I'm using a modififed version of the simple text widget that parses PHP too.
function the_qrcode($permalink = '', $title = '') {
if($permalink && $title == '') {
$permalink = 'http://eternityofgamers.com/forums';
$title = 'Forums';
}
echo '<img src="http://api.qrserver.com/v1/create-qr-code/?data=' .$permalink. '" alt="QR: ' .$title. '"/>;
}
Can someone tell me what's wrong with this? I get a 500 error when I add it to functions.php.
Look at StackOverflow's syntax highlighting. You're missing a closing single quote ' on your string at the end of the function's last line:
echo '<img ...' .$title. '"/>;
^
Close the last single quote on the echo line to be:
echo '<img src="http://api.qrserver.com/v1/create-qr-code/?data=' .$permalink. '" alt="QR: ' .$title. '"/>';

Categories