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
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
If I use the below code, I get the literal string <b> DATE: <?php echo $date; ?> </b> appended to content:
$content .= '<b> DATE: <?php echo $date; ?> </b>';
$pdf->writeHTML($content);
How can I instead get the value of $date there?
You are trying to put php code inside a string which will not be evaluated again. Try this:
$content .= '<b> DATE: ' . $date . '</b>';
$pdf->writeHTML($content);
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.
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 8 years ago.
Improve this question
What am I doing wrong¿?
echo "<img src= 'vestido'.$id.'.jpg' height=500 width=500 >";
I dont know how to concatenate this correctly.
Thank you very much
Basic PHP: If you start a string with one type of quotes e.g. ", you have to END the string with the same type of quotes. PHP is not recursively executable, nor will PHP look inside strings for PHP operators, like concatenation .'s.
You have:
echo "<img src= 'vestido'.$id.'.jpg' height=500 width=500 >";
^---start of string ^--end of string
when it should be
echo "<img src= 'vestido" . $id . ".jpg' height=500 width=500 >";
^--start ^--stop ^---start ^--stop
Your mixing " and '
With " for simple variables you do not need to concat
For ' you have done it correct either replace the start and end " with ' or remove the concat
You are opening your string with a double quote and attempting to close (in order to add a variable) with a single quote. This is not required as you can put variables directly into double quoted strings;
echo "<img src= 'vestido{$id}.jpg' height='500' width='500' >";
In this case I've added curly brackets around the variable to make this obvious. You might need to do this if your variable is immediately followed by a character that is valid in a variable (such as a number or letter) rather than one that isn't (such as a space, hyphen, or dot).
Hope this helps.
You can just insert $id within the echo
<?php
$id=5;
echo "<img src= 'vestido$id.jpg' height=500 width=500 >";
?>
will yield <img src= 'vestido5.jpg' height=500 width=500 >
Based on your code it looked like you wanted to do echo "<img src= 'vestido" . $id . ".jpg' height=500 width=500 >"; which would work as well
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 8 years ago.
Improve this question
How do i remove underscore from this echo?
if($validation->fails())
{
echo '<div class="error_message">', ($validation->errors()->first('first_name')), '</div>';
}
Thank you.
what madness is this?
if($validation->fails()) {
echo '<div class="error_message">' . str_replace("_"," ",($validation->errors()->first('first_name'))) . '</div>';
}
To replace a string char you have to use str_replace function.
Here is an example:
$var = "Hello_World";
$var = str_replace("_"," ",$var);
echo $var;
Output:
Hello World
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>";