echo "<p id='xlday'>'$_POST['day']'</p>";
Hi can anyone help me solve this problem, should be a simple one but i'm struggling for some reason!
Thanks
echo "<p id='xlday'>".$_POST['day']."</p>";
echo "<p id='xlday'>".$_POST['day']."</p>";
or
echo "<p id='xlday'>{$_POST['day']}</p>";
or
echo "<p id='xlday'>${_POST['day']}</p>";
or
echo "<p id='xlday'>$_POST[day]</p>";
I'll also add
echo "<p id='xlday'>", $_POST['day'], "</p>";
with the mention that it does not actually concatenate the strings, but rather outputs them one at a time.
Do like this:
echo "<p id='xlday'>".$_POST['day']."</p>";
You can also do like:
echo "{$_REQUEST['day']}";
However we prefer output buffering.
http://www.suite101.com/content/output-buffer-in-php-a26768
Related
I am working on my college web design course during my easter break and have run into a problem...
I have a menu on each page that I have removed from the html pages and written into a php file and that is used with an include in each page. Everything works fine apart from the onclick events that when clicked SHOULD load another page but at the moment does not do anything.
Here is my php file...
<?php
echo "<div id='leftPnl'>";
echo "<div class='navcon'>";
echo "<button class='static'
onclick='window.location.href='"."./index.html'".">Home</button>";
echo "<button class='accordion'>Gallery</button>";
echo "<div class='panel'>";
echo "<button class='static' onclick='window.location.href='"."./html/countryside.php'".">Countryside</button>";
echo "<div id='socialmedia'>";
echo "<img src='../images/sitewide/map.png'>";
echo "<br>Contact us on...<br>";
echo "<a class='fab fa-facebook-square fa-2x'
onclick='msg('"."Facebook"."')"."></a>";
echo "<a class='fab fa-instagram fa-2x' onclick='msg('"."Instagram"."')".">
</a>";
echo "<a class='fab fa-twitter-square fa-2x'
onclick='msg('"."Twitter"."')"."></a>";
echo "<a class='fab fa-tumblr-square fa-2x' onclick='msg('"."Tumblr"."')".">
</a>";
echo "<div id='clock'>";
echo "<p class='date'>{{ date }}</p>";
echo "<p class='time'>{{ time }}</p>";
echo "</div>";
echo "</div>";
echo "</div>";
?>
on running the file and inspecting the element in Chrome, the url that the href uses is not formatted correctly the ./ are missing and a single quote is also missing.
Is it simply that I am getting confused with the position of my single and double quotes in the php?
Thanks.
PS, I apologise if this has already been asked - I looked and could not find the answer.
Is it simply that I am getting confused with the position of my single and double quotes in the php?
Yes.
Look at the output of the PHP. To take one example:
onclick='msg('Facebook')>
You start the attribute value with '.
Then you try to use ' inside it.
Then you forget the ' at the end!
There is no reason to nest any of this code inside PHP string literals. All that achieves it making it harder to debug.
Just write the HTML directly, outside of <?php ... ?> sections.
It wouldn't be a bad idea to get rid of the intrinsic event attributes too, and use JavaScript to bind event handlers.
I have code like this in php
echo get($contents,'<plaintext>','</plaintext>') ;
it gives me the simple plain text.
Now i want to format this echo text with increase the font size
therefore i try
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>get($contents,'<plaintext>','</plaintext>') </div>";
but it is not working how to do this??
I try this by doing more experiment but none of the things working.
plz help me on this
You need to append the function in the string. Just like this:
echo "<div style ='font:30px Arial,tahoma,sans-serif;color:#555'>" . get($contents,'<plaintext>','</plaintext>') . "</div>";
I have the following line of code which doesn't seem to be working:
echo "<img src='/images/albumart'"; echo $row['art1']; echo "/>";
The 'art1' is definitely returning '/imagename.png' so the URL should be complete however nothing being displayed.
Any ideas?
Thanks.
You really should be concatenating that string:
<?php
echo '<img src="/images/albumart'.$row['art1'].'"/>';
?>
and ideally break out of php to do this:
<img src="/images/albumart<?php echo $row['art1']; ?>"/>
If you're not familiar, the period in php joins strings. That's called concatenation. No need to echo little bits like that, in fact please never do it the way you demonstrate. The root of your issue is, as Geoff pointed out, you weren't closing the src param.
echo "<img src='/images/albumart'"; echo $row['art1']; echo "/>";
It looks like you are closing the img src paramter after the albumart part.,
try this:
echo "<img src='/images/albumart"; echo $row['art1']; echo "' />";
I'm setting up a weather page using the wunderground.com API. Anyway, I want to do the following:
Of the variable $weather is equal to Clear, I want to display an image.
I've tried this:
if ($weather=="Clear") echo <img src="http://example.org/clear.gif" alt="Clear"/>
What do I need to do instead?
Try this
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
The code you tried will render ERROR. You need to place the HTML text and any string within quotes, before you echo them.
if ($weather=="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>'
Remaining, there is nothing else to improve :)
if ($weather==="Clear")
echo "<img src=\"http://example.org/clear.gif\" alt=\"Clear\"/>";
echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
OR
echo "<img src='http://example.org/clear.gif' alt='Clear' />";
if ($weather=="Clear") echo "<img src=\"http://example.org/clear.gif\" alt=\"Clear\"/>";
OR
if ($weather==="Clear") echo '<img src="http://example.org/clear.gif" alt="Clear"/>';
OR
if ($weather==="Clear") echo <<<ABC
<img src="http://example.org/clear.gif" alt="Clear"/>
ABC;
andsoon.
For conditionally rendering html, I often just use the php tags...
if($weather === "Clear") {?>
<img src="http://example.org/clear.gif" alt="Clear"/>
<?php}
This question already has answers here:
Print string with a php variable in it
(4 answers)
Closed 11 months ago.
How would I write this so I'm only using one echo?
echo "<div class='post'>";
echo $row['title'];
echo "</div>";
I'm using an array to echo out a table's values but it would be a lot easier on the eyes if I could combine these into one echo statement. However, when I try to the page goes blank.
echo "<div class=\"post\">{$row['title']}</div>";
Other ways of doing the same thing:
echo '<div class="post">'.$row['title'].'</div>';
echo sprintf('<div class="post">%s</div>', $row['title']);
<div class="post"><?php echo $row['title'] ?></div>
you forgot to close the div
> echo "<div class='post'"; should be
> echo "<div class='post'>";
Enclose the array reference in brackets:
echo "<div class='post'{$row['title']}</div>";
<?php
echo "<div class='post'".$row['title']."</div>";
?>
echo '<div class="post">' . $row['title'] . '</div>';
The . operator concatenates strings. Also, I believe HTML wants you to use double quotes for class="post" (although perhaps it doesn't care?).