Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果是移动/平板电脑,则替换css_Php_Css_Mobile_Replace_Detection - Fatal编程技术网

Php 如果是移动/平板电脑,则替换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-&gt;isMobile()) {$mobile = '1';} if ($mobile == 1) {

我正在使用Mobile detect,当手机或平板电脑浏览网站时,我想删除custom.css

有人能解释我做错了什么吗

<?php 

// Include and instantiate the class.
require_once 'php/mobile_detect.php';

$detect = new Mobile_Detect();
if ($detect-&gt;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-&gt;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">';
    }

?>