有没有更好的方法来写这个PHP代码? [英] Is there a better way to write this php code?

查看:127
本文介绍了有没有更好的方法来写这个PHP代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

return'
    <li>
    <a href="nano.com/' . $username . '"><img class="avatar" src="images/' . $picture . '" width="48" height="48" alt="avatar" /></a>
    <div class="tweetTxt">
    <strong><a href="nano.com/' . $username . '">' . $username . '</a></strong> '. autolink($tweet).'
    <div class="date">'.relativeTime($dt).'</div><div class="date">'. $reply_info . '</div> <a class ="reply"  href="home.php?replyto=@'. $username .'&status_id='. $id .'&reply_name=' .$username.'"> reply </a>

    </div>
    <div class="clear"></div>
    </li>';

我想知道是否有更清晰的方式来编写这段代码,并且考虑到处理时间,如果这真的意味着什么。

I was wondering if there is a cleaner way to write this code, and taking in mind processing time, if that really means anything.

ps这段代码是一个函数的一部分,这是return语句!

p.s. this code is part of a function, this is the return statement!

推荐答案

您可以使用HEREDOC语法:

You could use HEREDOC syntax :

$auto = autolink($tweet);
$rel = relativeTime($dt);
return <<<ENDOFRETURN
    <li>
    <a href="nano.com/$username"><img class="avatar" src="images/$picture" width="48" height="48" alt="avatar" /></a>
    <div class="tweetTxt">
    <strong><a href="nano.com/$username">$username</a></strong> $auto
    <div class="date">$rel</div><div class="date">$reply_info</div> <a class ="reply"  href="home.php?replyto=@$username&status_id=$id&reply_name=$username"> reply </a>
    </div>
    <div class="clear"></div>
    </li>
ENDOFRETURN;

这篇关于有没有更好的方法来写这个PHP代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆