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>';
?>
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 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 7 years ago.
Improve this question
<?php
function show(){?>
<?php echo "a"; ?> <br />
}
//this function is in another file
<?php
echo str_replace("<br />"," ",show());//search for <br />
?>
How i can replace the <br /> with " "?
You need to buffer the output. Something similar to this:
ob_start();
show();
echo str_replace("<br />", " ", ob_get_clean());
You can use a callback in combination with ob_start. The callback will be called each time the output is flushed.
function replace_br($buffer)
{
return preg_replace('~<br\b[^>]*>~i', ' ', $buffer);
}
ob_start('replace_br');
The regular expressions says:
find the string '
the char after should not be alphanumeric
find any characters others than '>'
find an '>'
This replaces <br>, <BR>, <br/>, <br /> but also something like <br class="clearfix">.
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 does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
hello I am creating my own theme on wordpress and i want to split the the_title() function into array all i want is the last item on array will be on <span> and the other one is on <h1>.
i tried this
$str = the_title();
$val = explode(" ", $str); // also tried implode
echo "<pre>";
print_r($val);
echo "</pre>";
but it only return array with no items
hope someone will help me.
this wat i really want to be the output
<h1> This is a <span>Title</spam></h1>
thanks in advance
Dont use the_title() as it automatically display the current title of the page.
Beside this Use $post->post_title;.
Lets suppose a sample sentence This is a Title
<?php
global $post;
$str = $post->post_title;
$exp = explode(" ",$str);
echo "<h1>".$exp[0].$exp[1].$exp[2];
echo "<span>".$exp[3]."</span></h1>";
?>
Output will be:
<h1>This is a<span>title</span></h1>
Please use get_the_title() instead of the_title().
Beside is the link for complete understanding :--
http://codex.wordpress.org/Function_Reference/get_the_title
Use following instead of $str = the_title();
$str = get_the_title();
-or-
$str = the_title('', '', false);
documentation : http://codex.wordpress.org/Function_Reference/get_the_title