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);
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 4 years ago.
Improve this question
my str is :
999999999
Now, how can i add "-" in this str ?
my example with "-" :
99-9-9-99999
Try this code -
<?php
$str = "999999999";
$output = substr($str,1,2)."-".substr($str,2,1)."-".substr($str,3,1)."-".substr($str,4,5);
echo "$output";
?>
output - 99-9-9-99999
You can use preg_replace() to format the number.
<?php
$num = "999999999";
$new_num = preg_replace("/([0-9]{2})([0-9]{1})([0-9]{1})([0-9]{5})/", "$1-$2-$3-$4", $num);
echo $new_num;
?>
Output:
99-9-9-99999
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 8 years ago.
Improve this question
I have a small program designed to out put the date
<?php
echo '<p>Ordered on ';
echo date('F jS g:iA');
echo '</p>';
?>
This outputs "Ordered on December 6th 5:25PM", how do i get the function to output "Ordered on December 6th at 5:25PM" instead?
This should work for you:
echo '<p>Ordered on ';
echo date('F jS \a\t g:iA');
echo '</p>';
try this:
<?php
echo '<p>Ordered on ';
echo date('F jS'), ' at ', date('g:iA');
echo '</p>';
?>
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 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.