Php 根据车身等级包括

Php 根据车身等级包括,php,html,if-statement,Php,Html,If Statement,我试图弄清楚如何在body标记上检查单个类,然后包含一个文件 Myheader.php包含: </head> <?php $class = BODY_CLASS; ?> <body class="<?php echo $class; ?>" id="top"> 只需稍微更改if语句,并将explode()您的$class拆分一个空格,然后在数组中搜索带有in_array()的值,例如 if (in_array("work", explode("

我试图弄清楚如何在body标记上检查单个类,然后包含一个文件

My
header.php
包含:

</head>
<?php $class = BODY_CLASS; ?>
<body class="<?php echo $class; ?>" id="top">


只需稍微更改if语句,并将
explode()
您的
$class
拆分一个空格,然后在数组中搜索带有
in_array()
的值,例如

if (in_array("work", explode(" ", $class))) {

只需稍微更改if语句,并将
explode()
您的
$class
拆分一个空格,然后在数组中搜索带有
in_array()
的值,例如

if (in_array("work", explode(" ", $class))) {

您可以使用不同的方法,例如,如果您确定
body
class始终是第一个单词,您可以尝试以下方法

$class=current(explode(" ",BODY_CLASS)); //class that you should check
if($class=='')

它拆分
BODY\u类
字符串并获取第一个值

无论如何,您也可以尝试搜索数组,如下所示

if(in_array('classname',explode(" ",BODY_CLASS)))

您可以使用不同的方法,例如,如果您确定
body
class始终是第一个单词,您可以尝试以下方法

$class=current(explode(" ",BODY_CLASS)); //class that you should check
if($class=='')

它拆分
BODY\u类
字符串并获取第一个值

无论如何,您也可以尝试搜索数组,如下所示

if(in_array('classname',explode(" ",BODY_CLASS)))

您可以将
分解
与\u数组中的
一起使用

if(isset($class)和&in_数组('work',explode('',$class)){…

参考资料:

您可以在数组中使用
explode

if(isset($class)和&in_数组('work',explode('',$class)){…

参考资料:

您只需要第一个类名吗?您只需要第一个类名吗?