我是网站用的是thinkphp的、
然后怎么判断类名.info在这个_shop.html的时候就消失。
比如:
news_shop.html
product_shop.html
类名.info在html名称是_shop.html的时候就消失
html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>判断变化title>
<style>
.info {
width: 200px;
height: 200px;
background-color: red;
}
style>
head>
<body>
<div class="info">div>
body>
html>
参考GPT和自己的思路:
很抱歉,从您的问题描述中我们并没有看出与 PHP 判断文件名有关的问题。不过从您提供的代码中,可以看出您想要消除 info
类名在 _shop.html
文件名中出现的情况。解决方法如下:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>判断变化</title>
<style>
.info:not([class*= "_shop"]) {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="info"></div>
</body>
</html>
上面的 CSS 代码中,我使用了属性选择器 [class*= "_shop"]
来匹配所有类名中包含 _shop
的元素。然后在 .info
类名前添加 :not()
伪类并加入属性选择器的规则,表示在不含有 _shop
的类名下才应用 .info
类名,达到了消除 info
类名在 _shop.html
文件名中出现的目的。
参考GPT和自己的思路:
你可以通过使用PHP的字符串函数来判断文件名中是否包含特定的字符串,并使用一些逻辑来做出相应的变化。
例如,以下PHP代码可以检查文件名是否包含“.info”字符串(这里假设变量$filename保存了文件名),并在包含时从文件名中删除它:
if (strpos($filename, '.info') !== false && strpos($filename, '_shop.html') !== false) {
$filename = str_replace('.info', '', $filename);
}
这个代码会检查文件名是否同时包含“.info”和“_shop.html”字符串,如果是,就使用str_replace函数将“.info”字符串替换为空字符串。
如果你要应用到ThinkPHP中,可以在模板中使用PHP代码块,将上面的代码放在需要判断的文件名上方即可。
<?php
$filename = 'product_shop.html';
if (strpos($filename, '.info') !== false && strpos($filename, '_shop.html') !== false) {
$filename = str_replace('.info', '', $filename);
}
?>
然后你可以在HTML中使用这个变量来表示文件名。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>判断变化</title>
<style>
.info {
width: 200px;
height: 200px;
background-color: red;
}
</style>
</head>
<body>
<div class="info"><?php echo $filename; ?></div>
</body>
</html>