我正在从库中将数据加载到视图中,但是获得的输出未格式化,我需要格式化的输出,我该如何实现呢?
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
echo '<title>'.$seo_data[0]->META_TITLE.'</title>'
.'<meta name="description" content="'.$seo_data[0]->META_DESCRIPTION.'" />'
.'<meta name="keywords" content="'.$seo_data[0]->META_KEYWORDS.'" />'
.'<meta name="url" content="'.$seo_data[0]->META_URL.'" />'
.'<meta name="copyright" content="'.$seo_data[0]->META_COPYRIGHT.'" />';
我获得了什么输出
<title>Test</title><meta name="description" content="Test." /><meta name="keywords" content="Test" /><meta name="url" content="Test" /><meta name="copyright" content="Test" />
这是必需的输出
<title>Test</title>
<meta name="description" content="Test." />
<meta name="keywords" content="Test" />
<meta name="url" content="Test" />
<meta name="copyright" content="Test" />
答案 0 :(得分:3)
希望这对您有帮助:
使用CI html helper
代替传统方式,像这样在autoload.php
中加载html helper
$autoload['helper'] =array('html');
并使用html meta
这样:
<?php
$meta = array(
array(
'name' => 'description',
'content' => $seo_data[0]->META_DESCRIPTION
),
array(
'name' => 'keywords',
'content' => $seo_data[0]->META_KEYWORDS
),
array(
'name' => 'url',
'content' => $seo_data[0]->META_URL
),
array(
'name' => 'copyright',
'content' => $seo_data[0]->META_COPYRIGHT
)
);
echo meta($meta);
?>
更多信息:https://www.codeigniter.com/user_guide/helpers/html_helper.html#meta