PHP echo filename into img src [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 8 years ago.
Improve this question
I have a image filename stored and i want to echo it into some code where it will be a hyperlink to another page but it also gets the filename from the stored data.
echo " <a href=\"ProductDescription.php?productid=" . $row['productid'] . \" >
<img src=\"/admin/images/ . $row['image'] . \" alt=\"product image\" width=\"40\"
height=\"65\"></a> ";
The error I'm getting is
Parse error: syntax error, unexpected '"', expecting T_STRING
I just can't seem to figure out my syntax problem to get it to work.

just check your double-quotes
echo " ";

You forgot to add the " after productid. And also forgot to add it around image.
Do it via:
echo "<img src=\"/admin/images/$row['image']\" alt=\"product image\" width=\"40\" height=\"65\">";
Or
echo " ";

This should fix the error:
echo " <a href=\"ProductDescription.php?productid=" . $row['productid'] . " \" ><img src=\"/admin/images/" . $row['image'] ."\" alt=\"product image\" width=\"40\"
height=\"65\"></a> ";

Related

php echo div class not working [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 am trying to echo a div class <div class="Box"> but not working. Can anyone help? Thanks.
echo '<div class="Box">
echo Anchor(T('Edit My Account'), '/profile/edit', FALSE, array('class' => 'Popup EditAccountLink'));
echo "<br />";
echo Anchor(T('Change My Password'), '/profile/password', FALSE, array('class' => 'Popup PasswordLink'));
echo "<br />";
$Inbox = 'Inbox';
$CountUnreadConversations = $Session->User->CountUnreadConversations;
if (is_numeric($CountUnreadConversations) && $CountUnreadConversations > 0)
$Inbox .= ''.$CountUnreadConversations.'';
echo Anchor(T('Inbox'), '/messages/all', 'Inbox');
</div>'
Your first and last lines are wrong, missing proper quotation marks and also an echo on the last line. It should be:
echo '<div class="Box">';
.... rest of code here...
echo '</div>';
You haven't terminated the string with ';.
echo '<div class="Box">';
Enable the error_reporting to E_ALL. Read on documentation. After this, you know what is happen.
This is a parse error. Enable error_reporting to E_ALL.

single quotes vs double quotes, how to arrange? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
Please let me know how to writte the below code so as to work because as it is it doesn't work
echo "<a href='$row['url']'>$row['link_text']</a>";
Write so you can read it next time. Also syntax highlight is better this way:
echo '' . $row['link_text'] . '';
You are using ' twice, so you need to escape them or just remove them in this case:
echo "<a href='$row[url]'>$row[link_text]</a>";
When you have to insert complex variables like array values inside strings, usually printf or sprintf is more clear and less error-prone.:
printf("<a href='%s'>%s</a>", $row['url'], $row['link_text']);
This will work:
echo "<a href='".$row['url']."'>".$row['link_text']."</a>";
Also this:
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
It's personal preference.
It's because you've put a ' inside another '.
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
or
echo "<a href='" . $row['url'] . "'>" . $row['link_text'] . "</a>";
Choose the one more to your liking.
You can try with.
echo "<a href='".$row['url']."'>".$row['link_text']."</a>";
Or
echo "<a href='{$row['url']}'>{$row['link_text']}</a>";
Or
echo ''.$row["link_text"].'';

Simple php in footer not working to call some styling and an url [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 using wordpress, and I'm having a hard time with a simple php code I want to add in footer.php to display a "|" symbol with 20px of margin and a url only on the site frontpage:
<?php
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span><a href="http://www.w3schools.com" target='_blank' title='W3C'>Visit W3Schools</a>";
}
?>
The following characters are displayed in green by my txt editor as if they were comments:
" target='_blank' title='W3C'>Visit W3Schools</a>";
With the code above, I'm getting a php error:
PARSE ERROR: SYNTAX ERROR, UNEXPECTED 'HTTP' (T_STRING), EXPECTING ',' OR ';'
This, is working:
<?php if( is_front_page() ) echo 'Visit W3Schools';?>
And this, is working too:
<?php
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span>";
}
?>
But somehow I can't combine these two codes. What am I missing here?
You are going out of "PHP" with the double quote there. You can use this:
echo "<span style='margin: 0 20px;'>|</span><a href='http://www.w3schools.com' target='_blank' title='W3C'>Visit W3Schools</a>";
You had to use single quotes. You can't use both when going into "String" mode. If you want to use double quote you have to escape it like (with a \):
echo "<span style='margin: 0 20px;'>|</span><a href=\"http://www.w3schools.com\" target='_blank' title='W3C'>Visit W3Schools</a>";
The reason it is being commented out is because of your quotes. You have to either use single quotes around your double quotes or escape your quotes.
Here:
<?php
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span><a href=\"http://www.w3schools.com\" target='_blank' title='W3C'>Visit W3Schools</a>";
}
?>
You need to escape " characters with \
if(is_front_page()){
echo "<span style='margin: 0 20px;'>|</span><a href=\"http://www.w3schools.com\" target='_blank' title='W3C'>Visit W3Schools</a>";
}
?>
<?php
if(is_front_page()){
echo '<span style="margin: 0 20px;">|</span>';
echo 'Visit W3Schools';
}
?>

PHP Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
Could someone correct this code:
echo "<div style="float:right;"><a href='index.php?img1=$img1_id&img2=$img2_id'><img src='$img1_url' /></a></br>Asd: $img1_asd</div>";
echo "<div style="float:right;"><a href='index.php?img1=$img2_id&img2=$img1_id'><img src='$img2_url' /></a></br>Asd: $img1_asd</div>";
I'm getting the error which is specified in the title
Learn Escape Sequence .
echo "<div style=\"float:right;\"><a href='index.php?img1=$img1_id&img2=$img2_id'><img src='$img1_url' /></a></br>Asd: $img1_asd</div>";
echo "<div style=\"float:right;\"><a href='index.php?img1=$img2_id&img2=$img1_id'><img src='$img2_url' /></a></br>Asd: $img1_asd</div>"
echo '<div style="float:right;"><a href="index.php?img1='.$img1_id.'&img2='.$img2_id.'><img src='.$img1_url.' /></a></br>Asd: '.$img1_asd.'</div>';
echo '<div style="float:right;"><a href="index.php?img1='.$img2_id.'&img2='.$img1_id.'><img src='.$img2_url.' /></a></br>Asd: '.$img1_asd.'</div>';
Come on you can do better...
echo "<div style='float:right;'>",
"<a href='index.php?img1=", $img1_id, "&img2=", $img2_id, "'>",
"<img src='", $img1_url, "' />",
"</a><br />",
"Asd: ", $img1_asd",
"</div>";
This even has & correctly escaped to &
Remember, closing void tags is only neccessary for XHTML: <br />
not in HTML4 and HTML5.
This is even wrong³: </br>

echo inside an echo - does it work? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
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.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Improve this question
It's been a long time since I have done php so sorry for the silly question.
This is my current code, I'm trying to save the URL as a variable so that I can insert it into the echo, but it doesn't seem to work as nothing appears:
<?php ob_start();
echo get_post_meta($post->ID, 'oldurl', true);
$old_url = ob_get_contents();
ob_end_clean();
?>
<?php echo do_shortcode('[fbcomments][fbcomments url="$old_url" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
I have echoed $old_url and can see that it has the correct value, but how do I insert the value into the echo do_shortcode with url="$old_url"?
This doesn't work either:
<?php echo do_shortcode('[fbcomments][fbcomments url="echo $old_url;" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
You'll need to switch your quotes around. Single quotes print everything out as-is. Double-quotes will process the variables. Also, echo is not needed within an echo.
<?php echo do_shortcode("[fbcomments][fbcomments url='$old_url' width='375' count='off' num='3' countmsg='wonderful comments!']"); ?>
Another way to do it without switching your quotes is to break out of the statement:
<?php echo do_shortcode('[fbcomments][fbcomments url="'.$old_url.'" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Variables are not replaced in single quotes ...
<?php echo do_shortcode('[fbcomments][fbcomments url="' . $old_url . '" width="375" count="off" num="3" countmsg="wonderful comments!"]'); ?>
Singles quotes doesn't allow variables parsing.
For example :
$var = 'Hello';
echo 'The content of my var is : $var';
// Will output : "The content of my var is : $var"
echo "The content of my var is : $var";
// Will output : "The content of my var is : Hello"
So you have to use double quotes or use the concatenate operator : .

Categories