字符串PHP拼写错误[关闭]

PHP spelling frustrated me. I keep trying to add ". ABC ." and '. ABC .'. But it still doesnt work. Like my code below:

echo '
    <div class="box">
       <p> '.$obj->name.': "'.$obj->message.'" </p>
       <p class="right"> '.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.' </p> 
    </div>
';

The problem is DATE FORMAT doesn't want to show on a webpage. Any idea?

Change

'.date_format('.$obj->message_date.', 'Y-m-d H:i:s');.'

to

'.date_format($obj->message_date, 'Y-m-d H:i:s').'

If $obj->message_date is a string, you need to convert it to a date object first:

'.date_format(date_create($obj->message_date), 'Y-m-d H:i:s').'

The issue you are having is you are not concatenating your PHP into your string correctly.

       echo '
        <div class="box">
           <p> '.$obj->name.': "'.$obj->message.'" </p>
           <p class="right"> '.date_format($obj->message_date, "Y-m-d H:i:s").' </p> 
        </div> ';

I think this should not provide errors on that front. If the page still doesn't load you will need to look at the $obj to see if there is actually a message_date property and that is a date.

For more information see http://php.net/manual/en/language.operators.string.php