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
im having trouble using an image search within php tags, is it possible?
My code bellow:
<?php
echo "<div id=reviewname>Name: ".$dname['name']."</div>";
echo "<div id=reviewseat>Seat: ".$dseat['seat']."</div>";
echo "<div id=srating>Sound: ".$dsrating['s_rating']."</div>";
echo "<div id=crating>Comfort: ".$dcrating['c_rating']."</div>";
echo "<div id=vrating>View: ".$dvrating['v_rating']."</div><br /><br/>";
echo "<div id=reviewcomment> Comments: ".$dcomment['comment']."</div>";
?>
I would like within these div's to be an image src example being:
echo "<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: ".$dsrating['s_rating']."</div>";
The above does not work, is it a syntactical issue?
Thanks
You need to escape the quotes inside the echo statement
echo "<div id=srating><img src=\"images/soundimg.png\" alt=\"Sound\" height=\"35\" width=\"35\"></div>Sound: ".$dsrating['s_rating']."</div>";
If not escaping, you can also use single quotes for attribute values.
echo "<div id=srating><img src='images/soundimg.png' alt='Sound' height='35' width='35'></div>Sound: ".$dsrating['s_rating']."</div>";
If you need to echo and in string u need to put " quotes, you can use single quote around ur string.
echo '<div id=srating><img src="images/soundimg.png" alt="Sound" height="35" width="35"></div>Sound: '.$dsrating['s_rating'].'</div>';
same for single quote.
But if you need both single & double quotes you can use any method and use \' or \"
Or you can have a very useful too, heredoc syntax.
Related
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 am trying to display an image using a variable "$images" that contains the URL parsed form an API.
This is my code:
echo "<td>""<img src='",$image,"'>""</td>\n";
I assume there is a typo I cannot detect because I get a blank screen when running this.
echo "<td>"."<img src='".$image."'>"."</td>";
Or
echo "<td><img src='".$image."'></td>";
You were missing the dots/commas after/before the td tags
use . not ,
<img src='".$image."'>
PHP requires that you chain your strings together using a .
E.g.
echo 'Test' . ' ' . 'Hello'; // Test Hello
Or simply :
echo "<td><img src='$image'></td>";
Check documentation.
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
Hi guys can anyone help to figure out what's wrong in my code it showing unexpected ','
$list1 .= '<tr onmouseover="this.style.backgroundColor=','#ffff66',';" onmouseout="this.style.backgroundColor=','#d4e3e5',';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';
, is used for passing multiple parameters to echo, not for concatenating strings to add to be stored in a variable. use . instead
You can rewrite it like this, escaping the single quotes in the javascript:
$list1 .= '<tr onmouseover="this.style.backgroundColor=\'#ffff66\';" onmouseout="this.style.backgroundColor=\'#d4e3e5\';">
<td>'.$ver.'</td><td>'.$ver2.'</td>
</tr>';
You are not properly concatenating the string/escaping the quotes. You had unnecessary commas. My example also uses double quoted strings so you don't need concatenation
$list1 .= "<tr onmouseover=\"this.style.backgroundColor='#ffff66;'\"
onmouseout=\"this.style.backgroundColor='#d4e3e5'\">
<td>$ver</td><td>$ver2</td></tr>";
To avoid to escape quotes: you can use the heredoc syntax:
$list1 .= <<<EOD
<tr onmouseover="this.style.backgroundColor='#ffff66';" onmouseout="this.style.backgroundColor='#d4e3e5';">
<td>$ver</td><td>$ver2</td>
</tr>
EOD;
try this-
$list1 .= "<tr onmouseover='this.style.backgroundColor='#ffff66';' onmouseout='this.style.backgroundColor='#d4e3e5';'><td>".$ver."</td><td>".$ver2."</td></tr>";
working fine for me.
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
im getting this error but cannot figure out why
while($info = mysql_fetch_array( $data ))
{
echo itg_fetch_image('.$info['meta_value'].'); //the line giving error
Print "<tr>";
Print "<th>ID:</th> <td>".$info['meta_id'] . "</td> ";
Print "<th>VALUE:</th> <td>".$info['meta_value']. "</td> ";
Print "<th>DONE:</th> <td>YES</td> ";
}
if i comment out this line it shows fine in the value td, ive tried everthing. taking the dots out the taking the comments out then adding "". itg_fetch_image is http://www.intechgrity.com/automatically-copy-images-png-jpeg-gif-from-remote-server-http-to-your-local-server-using-php/#
the code is ment to be echo itg_fetch_image('url') and all meta_values return a url string
The quotes on the echo line are causing the problem.
It should look like this:
echo itg_fetch_image($info['meta_value']);
it seems that itg_fetch_image() is a function
try this:
echo itg_fetch_image($info['meta_value']);
you can just pass variable . do not need to use quotes.
You must write it as
echo itg_fetch_image($info['meta_value']);
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
how can I print out a variable name in text in php?
I want to accomplish something as simple as having this:
echo "|" . "$myvariable" . "|";
print out this:
|$myvariable|
instead of this:
||
how can I accomplish this?
Use single quotes so that the variables don't get interpolated:
echo "|" . '$myvariable' . "|";
As others pointed out, use single quotes to show the variable name "as is".
echo "|" . '$myvariable' . "|";
Be sure to read this part of the manual.
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.