ecarollo Posted March 4, 2013 Share Posted March 4, 2013 Hi there, I've been trying to figure out some PHP that will detect mobile, tablet and desktop. I'm so close... the problem is that the 'tablet' part of the code is also reading as a 'mobile' device. Is there a way to make the 'tablet' function ignore the 'mobile' function? P.S. I'm using the standard Mobile_detect.php Here's my code:[<?phpinclude_once "wa/includes/Mobile_Detect.php";$detect = new My_Mobile_Detect();?><!-- TABLET START --><?php if($detect->isTablet()) { ?> <div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div><!-- TABLET END --><?php } if($detect->isMobile()) { ?> <a href="tel:(206) 601-1904" style="float:left; position:right; position:relative;top:10px; left:100px; margin-bottom:-25px !important; text-decoration:none;" title="Call (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/phone_icon.png" width="90" height="90" alt="Call (206) 601-1904"></a> <a href="tel:(206) 601-1904" style="text-decoration:none;" title="Call (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 25px 0px 115px;line-height:1em;">Call<br />Us!</span></a> <a href="sms:2066011904" style="float:left; position:right; position:relative;top:10px; margin-bottom:-25px !important; text-decoration:none;" title="Text (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/text_icon.png" width="90" height="90" alt="Phone Icon"></a> <a href="sms:2066011904" style="text-decoration:none;" title="Text (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 0px 0px 20px;line-height:1em;">Text<br />Us!</span></a> <?php }else{ ?><!-- DESKTOP START --> <div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div><!-- DESKTOP END --><?php } ?>]Thanks in advance ecarollo Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/ Share on other sites More sharing options...
teynon Posted March 5, 2013 Share Posted March 5, 2013 (edited) Please wrap your code in code blocks. (<> button) <?php include_once "wa/includes/Mobile_Detect.php"; $detect = new My_Mobile_Detect(); ?> <!-- TABLET START --><?php if ($detect->isTablet()) { ?> <div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div> <!-- TABLET END --><?php } if ($detect->isMobile()) { ?> <a href="tel:(206) 601-1904" style="float:left; position:right; position:relative;top:10px; left:100px; margin-bottom:-25px !important; text-decoration:none;" title="Call (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/phone_icon.png" width="90" height="90" alt="Call (206) 601-1904"></a> <a href="tel:(206) 601-1904" style="text-decoration:none;" title="Call (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 25px 0px 115px;line-height:1em;">Call<br />Us!</span></a> <a href="sms:2066011904" style="float:left; position:right; position:relative;top:10px; margin-bottom:-25px !important; text-decoration:none;" title="Text (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/text_icon.png" width="90" height="90" alt="Phone Icon"></a> <a href="sms:2066011904" style="text-decoration:none;" title="Text (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 0px 0px 20px;line-height:1em;">Text<br />Us!</span></a> <?php } else { ?> <!-- DESKTOP START --> <div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div> <!-- DESKTOP END --><?php } ?> Edited March 5, 2013 by teynon Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/#findComment-1416617 Share on other sites More sharing options...
haku Posted March 5, 2013 Share Posted March 5, 2013 (edited) if ($detect->isTablet()) { // tablet } elseif($detect->isMobile()) { // mobile } else { // all the rest } Edited March 5, 2013 by haku Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/#findComment-1416710 Share on other sites More sharing options...
haku Posted March 5, 2013 Share Posted March 5, 2013 (edited) <?php include_once "wa/includes/Mobile_Detect.php"; $detect = new My_Mobile_Detect(); $tablet = '<div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div>'; $mobile = '<a href="tel:(206) 601-1904" style="float:left; position:right; position:relative;top:10px; left:100px; margin-bottom:-25px !important; text-decoration:none;" title="Call (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/phone_icon.png" width="90" height="90" alt="Call (206) 601-1904"></a>'; $mobile .= '<a href="tel:(206) 601-1904" style="text-decoration:none;" title="Call (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 25px 0px 115px;line-height:1em;">Call<br />Us!</span></a>'; $mobile .= '<a href="sms:2066011904" style="float:left; position:right; position:relative;top:10px; margin-bottom:-25px !important; text-decoration:none;" title="Text (206) 601-1904"><img src="http://www.legend-cars.com/wp-content/uploads/2012/11/text_icon.png" width="90" height="90" alt="Phone Icon"></a>'; $mobile .= '<a href="sms:2066011904" style="text-decoration:none;" title="Text (206) 601-1904"><span style="font-size:40px;float:left; margin:15px 0px 0px 20px;line-height:1em;">Text<br />Us!</span></a>'; $desktop = '<div style="float:right;position:relative;margin:35px 25px 40px 0px;font-size:40px">(206) 601-1904</div>'; if ($detect->isTablet()) { echo $tablet; } elseif ($detect->isMobile()) { echo $mobile; } else { echo $desktop; } You may want to start looking at your code like this. When you are jumping in and out of PHP tags and logic all the time, your code becomes difficult to read. Look at how I've structured your code here, and I think you'll find it's a little easier to read, which in turn will make it easier to debug when you are having issues. Edited March 5, 2013 by haku Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/#findComment-1416711 Share on other sites More sharing options...
ecarollo Posted March 5, 2013 Author Share Posted March 5, 2013 Thank you all so much... I'll give these suggestions a try and let you know how it turned out! Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/#findComment-1416758 Share on other sites More sharing options...
ecarollo Posted March 5, 2013 Author Share Posted March 5, 2013 You guys Rock!!! That worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/275249-need-help-with-mobile-detect-specifically-the-tablet-code/#findComment-1416787 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.