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.
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 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 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>";
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
I am designing a small application which shoots out status-like tweets from users at the five latest ones. To keep it a small application, I need for it to accept only so many characters on a line and the drop a line just below it. So for example:
Noah: The best thing about Stackoverflow
is that it is full of amazing programmers.
Something along the lines of something like that above. Can you help me with the code below :
echo "<div style='position:relative;top:-20px;padding-top:10px;padding-left:30px;padding-right:30px;'>";
echo "<p> $first_name: $body. </p>";
if (strlen($body <= 100)) {
echo "\n";
}
echo "</div>";
}
wordwrap will do that for you
string wordwrap ( string $str [, int $width = 75 [, string $break = "\n" [, bool $cut = false ]]] )
Example:
$text = "A very long woooooooooooord.";
$newtext = wordwrap($text, 8, "\n", true);
echo "$newtext\n";
A very
long
wooooooo
ooooord.