【发布时间】:2015-03-19 21:40:45
【问题描述】:
我需要以更好的方式执行此操作,或者修复我遇到的错误。 错误:解析错误:语法错误,意外的 '=>' (T_DOUBLE_ARROW),在第 15 行的 C:\xampp\htdocs\php\config.php 中需要 ')'
<?php
$meta_build = "<head>";
$meta = array(
array(
'type' => 'title',
'content' => 'Test'
),
array(
'type' => 'meta',
'name' => 'description',
'content' => 'Somestuff',
),
array(
'type' => 'meta',
'name' => 'viewport',
'content' => 'width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'
),
array(
'type' => 'text/css',
'link' => 'http://fonts.googleapis.com/css?family=Titillium+Web'
),
array(
'type' => 'css',
'link' => '/css/bootstrap.min.css'
),
array(
'type' => 'css',
'link' => '/css/bootstrap-theme.min.css'
),
array(
'type' => 'css',
'link' => '/css/main.css'
)
);
foreach($meta as $item){
if($item['type'] == 'title'){
$meta_build .= "<title>";
$meta_build .= $item['content'];
$meta_build .= "</title>";
}
if($item['type'] == 'meta'){
$meta_build .= "<meta";
$meta_build .= 'name="';
$meta_build .= $item['name'].'" content="';
$meta_build .= $item['content'].'"/>';
}
if($item['type'] == 'text/css'){
$meta_build .= '<link rel="stylesheet"';
$meta_build .= 'href="'.$item['link'].'"';
$meta_build .= "type='text/css'/>";
}
if($item['type'] == 'css'){
$meta_build .= '<link rel="stylesheet"';
$meta_build .= 'href="'.$item['link'].'"/>';
}
}
$meta_build .= "</head>";
echo $meta_build;
?>
【问题讨论】:
-
我执行了你的代码,使用 php 5.4.4 和 error_reporting(E_ALL) 得到了零错误。
-
在构建标签时可能需要放置空格。示例:'
-
你显示的文件也是config.php吗?
-
不,没有帮助。也许你可以帮我写一个有效的方法来用 php 构建我的元标记。不,该文件称为 head.php。耶稣我瞎了……或者我看不懂。