问题
I need to add "Uhr" at the end of the following Code:
<?
$doc = JFactory::getDocument();
$doc->setTitle($event->title . " | Example");
$doc->setDescription($event->title . " am " . $event->start, 'end' -> $event->end "uhr needs to be here");
?>
how can I archive this? Because if I add a .
"Uhr" it doesn't work :(
回答1:
$doc->setDescription($event->title . " am " . $event->start . ", " . $event->end . " Uhr");
should do it.
Formatted dates:
$doc->setDescription($event->title . " am " . date('d.m.Y', strtotime($event->start)) . ", " . date('H:i', strtotime($event->end)) . " Uhr");
回答2:
I think there is something wrong with the last ->
.
Maybe this works:
$doc->setDescription($event->title . " am " . $event->start, 'end' . $event->end . "uhr");
回答3:
In case "am"
, "end"
and "urh needs to be here"
, best you use the same quotes like:
<?
$doc = JFactory::getDocument();
$doc->setTitle($event->title . " | Tanzschule Hartung");
$doc->setDescription($event->title . " | Tanzschule Hartung" " am " . $event->start, "end" -> $event->end . "uhr needs to be here");
?>
(look at your text 'end', compared to the code above)
It looks like $event->start
(and others) need to display some text which is requested.
Why you need to use a .
(dot) after requesting text from another function is because PHP needs to understand when it has to display text or not.
The .
is the string concatenation operator.
This might work as well:
<?
$doc = JFactory::getDocument();
// Setting titles
$title = $doc->setTitle($event->title);
$start = $event->start;
$end = $event->end;
$doc->setDescription($title . " | Tanzschule Hartung am " . $start . " , end" . $end . "uhr needs to be here");
?>
I hope this clears something up.
If you have any questions, feel free to ask.
来源:https://stackoverflow.com/questions/47752038/how-to-set-a-third-operator-in-a-string-that-adds-the-text-uhr