Php 如果是移动/平板电脑,则替换css
我正在使用Mobile detect,当手机或平板电脑浏览网站时,我想删除custom.css 有人能解释我做错了什么吗Php 如果是移动/平板电脑,则替换css,php,css,mobile,replace,detection,Php,Css,Mobile,Replace,Detection,我正在使用Mobile detect,当手机或平板电脑浏览网站时,我想删除custom.css 有人能解释我做错了什么吗 <?php // Include and instantiate the class. require_once 'php/mobile_detect.php'; $detect = new Mobile_Detect(); if ($detect->isMobile()) {$mobile = '1';} if ($mobile == 1) {
<?php
// Include and instantiate the class.
require_once 'php/mobile_detect.php';
$detect = new Mobile_Detect();
if ($detect->isMobile()) {$mobile = '1';}
if ($mobile == 1) {
echo '<link href="'.$site.'css/mobile.css'" rel="stylesheet">';
}else {
echo '<link href="'.$site.'css/desktop.css'" rel="stylesheet">';
}
?>
更换
if ($detect->isMobile()) {$mobile = '1';}
与
看看这是否有效您的报价不匹配以及您的
->
有问题。试一试
if ($detect->isMobile()) {$mobile = '1';}
反而
对于不匹配的引号,请使用
echo '<link href="'+$site+'css/mobile.css" rel="stylesheet">';
echo';
我就是这么做的,而且很有效
// Include and instantiate the class.
require_once 'php/mobile_detect.php';
$detect = new Mobile_Detect();
if ($detect->isMobile()) {$mobile = '1';}
if ($mobile == 1) {
echo '<link href="css/mobile.css" rel="stylesheet">';
}else {
echo '<link href="css/custom.css" rel="stylesheet">';
}
?>
//包含并实例化该类。
需要_once“php/mobile_detect.php”;
$detect=新手机检测();
如果($detect->isMobile()){$mobile='1';}
如果($mobile==1){
回声';
}否则{
回声';
}
?>
发生了什么/没有发生什么?是的,这很有效!很酷,谢谢。但是现在我得到了一个未定义的错误变量:C:\wamp\www\test\index.php中的mobile在第10行调用堆栈1 0.0007 271704{main}()..\index.php:0第10行是这if($mobile==1){
Ok,如果我在线运行它,而不是使用wamp,我不会得到错误。
// Include and instantiate the class.
require_once 'php/mobile_detect.php';
$detect = new Mobile_Detect();
if ($detect->isMobile()) {$mobile = '1';}
if ($mobile == 1) {
echo '<link href="css/mobile.css" rel="stylesheet">';
}else {
echo '<link href="css/custom.css" rel="stylesheet">';
}
?>