[英]How can I put php code inside php function variable
I have a php function where is variable in which I need to put some php code:我有一个 php function 变量,我需要在其中放置一些 php 代码:
function likes() {
$postid = $_GET["videoid"];
$output = '<i if (userLiked($postid)): class="fa fa-thumbs-up like-btn" else: class="fa fa-thumbs-o-up like-btn" endif data-id=" echo $postid "></i>
<span class="likes"> echo getLikes($postid); </span>
<i if (userDisliked($postid)): class="fa fa-thumbs-down dislike-btn" else: class="fa fa-thumbs-o-down dislike-btn" endif data-id=" echo $postid "></i>
<span class="dislikes"> echo getDislikes($postid); </span>';
return $output;
}
You need to concatenate your HTML string, and your variables (shortened for brevity):您需要连接您的 HTML 字符串和您的变量(为简洁起见):
$output = '<i data-id="' .$postid .'"></i><span class="likes">' .getLikes($postid) .'</span>';
You might want to look at a templating system, and pass in your variables as props.您可能想查看模板系统,并将变量作为道具传递。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.