在公用PHP文件里做了个判断,需要混排PHP和HTML,自己不会写,麻烦大家帮忙改写一下这段,用PHP的标准写法是怎样的:
- PHP code
<?php if $id=1 { echo "<title> $row['p_name']; - 欢迎光临!</title> <meta name="keywords" content="$row['p_name'];,关键字测试" /> <meta name="description" content="$row['p_name'];,描述测试" /> "; } else { echo "<title>Welcome</title> <meta name="keywords" content="关键字测试" /> <meta name="description" content="描述测试" /> "; } ?>
谢谢!!!
------解决方案--------------------
还是这样吧:
- PHP code
<?php if( $id === 1 ) { echo "html <title> {$row['p_name']} - 欢迎光临!</title> <meta name=\"keywords\" content=\"{$row['p_name']},关键字测试\" /> <meta name=\"description\" content=\"{$row['p_name']},描述测试\" /> "; } else { echo " <title>Welcome</title> <meta name=\"keywords\" content=\"关键字测试\" /> <meta name=\"description\" content=\"描述测试\" />"; } ?>
------解决方案--------------------
<?php
$title = ''; $keywords = ''; $description = '';
if($id==1){
$title = $row['p_name'];
$keywords = $row['p_name'];
$description = $row['p_name'];
}?>
<title><?php echo $title;?></title>
<meta name="keywords" content="<?php echo $keywords;?>,关键字测试">
<meta name="description" content="<?php echo $description;?>,关键字测试">
------解决方案--------------------
- - 傻了,上面第一行应该是$title = 'Welcome'