Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
I am trying to echo my price field but I need a £ symbol before it, I have tried adding it to this line of code but i keep getting errors, help please!
echo "<td>" . $row['price'] . "</td>";
Try this"
echo "<td>" . $row['price'] . "£</td>";
Or instead of £ with HTML output you can always write
£
like this:
echo "<td>£". $row['price'] . "</td>";
echo "<td> £" . $row['price'] . "</td>";
You could add as well to get a standard amount with a comma seperating thousands
"<td> £" . number_format( $row['price']) . "</td>";
echo "<td> £" . $row['price'] . "</td>";
Related
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 1 year ago.
Improve this question
all I want to know what's the syntax error in this code.
echo "<p id='hide_text_$heading->id' >"preg_replace($rx, "<b>$0</b>", $heading->shortHeadline)"</p>";
Use . to concatenate strings. Change your code to
echo "<p id='hide_text_$heading->id' >" . preg_replace($rx, "<b>$0</b>", $heading->shortHeadline) . "</p>";
to concatenate the three parts or separate each statement:
echo "<p id='hide_text_$heading->id' >";
echo preg_replace($rx, "<b>$0</b>", $heading->shortHeadline);
echo "</p>";
More on String Operators
you forget concatination sympol => .
Also there is syntax error in $0 if you mean by that variable name.
variable name could not start with numbers
only _ and string characters as i remember.
echo "<p id='hide_text_".$heading->id."' >" . preg_replace($rx, "<b>.$0.</b>", $heading->shortHeadline) . "</p>";
You can read more about Concatenation
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
this is my first post and I am new to this community. I'm currently learning php, but facing an issue with paragraphs:
<?php
$name = "Erik Mustermann";
echo $name . "<br />";
echo strlen($name) . "<br />";
var_dump($name) . "<br />";
echo "Heyho" . "<br />";
var_dump($name) . "<br />";
?>
output:
Erik Mustermann
15
string(15) "Erik Mustermann" Heyho
string(15) "Erik Mustermann"
Why is the string "Heyho" in the same line like var_dump even I created a paragraph?
To be honest I'm surprised this code compiles.
With the code var_dump($name) . "<br />"; the second part . "<br />"; is not passed to var_dump and so it isn't output. What you want is:
var_dump($name . "<br />");
echo is not a function but a language construct which is why it doesn't required the braces.
As a side note, <br/> doesn't create a new paragraph, it creates a new line.
I have been using this syntax
print "<td>" . "$" . round($res->DollarValue) . "</td>";
Which will output something like this: $8812 I want the format to be $8,812 so I tried this
print "<td>" . "$" . round(number_format($res->AveragePrice)) . "</td>";
but that did not do the trick either.
What I am after is rounding with a dollar sign and comma, but no decimals.
Further Examples
1000.78 -> $1,001
1000.23 -> $1,000
What is the php synatx for this?
This question already has answers here:
How can I combine two strings together in PHP?
(19 answers)
Closed 7 years ago.
Googled but couldn't find an answer.
I have
echo "<input type = 'text' value = ".$value." name = ".$input_id."/>";
$value or $input_id contains a dot which is conflicting with the dot used for concatenation. How do I escape it?
Thanks!
If the variables contains eg. space, they has to be in quotes. Concat operators cause no problem.
echo "<input type='text' value='" . $value . "' name='" . $input_id . "'/>";
Use this
echo "<input type='text' value='" . $value . "' name='" . $input_id . "'/>";
I am having a problem trying to get a row to create everytime I enter a new database entry.
My code so far is:
<table align="center">
<th>MH/s</th><th>Contact Length</th><th>Date Bought</th><th>Payment</th>
<?php while ($row_cnt > 0) {
echo "<tr><td>" . $row['mhbought'] . "</td><td>" . $row['length'] . "</td><td>" . date(d-m-Y, $row['datebought'] . "</ td><td>" . $row['payment'] . "</td></tr>";
}
?>
</table>
The error I receive however states PHP Parse error: syntax error, unexpected ';' (which is the echo line) Am I doing something completely dumb here, can this even be done?
Thank you for any help you may provide.
Looking at the code, the problematic line is this:
date(d-m-Y, $row['datebought']
^^ missing quotes ^ missing closing parenthesis
Change it to:
date('d-m-Y', $row['datebought'])
You haven't close date() right bracket and there is quotation missing for date format. Your echo should look like:
echo "<tr><td>" . $row['mhbought'] . "</td><td>" . $row['length'] . "</td><td>" . date('d-m-Y', $row['datebought']) . "</td><td>" . $row['payment'] . "</td></tr>";