php - 如何在 html 标签中正确包装 php 变量?
问题描述
我不是真正的 php 专家,我想做的是将 $duration 变量包装在 span 标签内的最后一行,这样我就可以设置它的样式。
<?php
$duration = '';
if( function_exists( 'cbc_get_video_data' ) ){
global $post;
$video = cbc_get_video_data( $post );
if( $video ) {
$duration = $video->get_human_duration();
}
}
$title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . $duration . get_the_title() . '</h1>';
?>
当我做这样的事情时,网站会中断
<?php
$duration = '';
if( function_exists( 'cbc_get_video_data' ) ){
global $post;
$video = cbc_get_video_data( $post );
if( $video ) {
$duration = $video->get_human_duration();
}
}
$title_content .= '<div class="post-title-wrapper"><h1 class="post-title">' . '<span class="video-duration">'$duration'</span>' . get_the_title() . '</h1>';
?>
有什么建议么?
谢谢
解决方案
在您的第二个示例中,您.
缺少$duration
. 您也没有关闭 a<div>
并且不需要打开跨度之间的额外连接。
要优化此代码,请尝试以下操作:
$title_content .= '<div class="post-title-wrapper"><h1 class="post-title"><span class="video-duration">' . $duration . '</span>' . get_the_title() . '</h1></div>';
推荐阅读
- sql - 基于现有表字段创建 SQL 语句
- python - zeep 客户端异常。zeep.transport.session.cookies 不传播
- powershell - 是否可以检查 .cmd 运行的 powershell 脚本?
- python - 除了 subprocess.Open 之外,有没有办法从 python 调用“hadoop cp/distcp”?
- c# - C# Linq - 对已经分组的数据进行分组
- javascript - 如何在打字稿中访问geoJson坐标数组?
- vue.js - 路由器视图中的路由器视图
- c# - 使用 Firebase Auth 对其进行身份验证后,如何在最终用户 c# 应用程序中安全地使用 Google Speech API?
- python - 用 dict 值替换列表值中的列表
- c# - 无法使用本机 .SO 创建 Java 库绑定