Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8179811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:04:53+00:00 2026-06-07T00:04:53+00:00

This question is directly related to this SO question I posed about 15 minutes

  • 0

This question is directly related to this SO question I posed about 15 minutes ago. This is not intended to be a duplicate post of that one, rather hoping this is more of a learning experience.

In the question posed, I was trying to figure out what was causing a preg_match no deliminator found error. The code (which is not mine) is available here. The error ended up being a missing ‘/i’ in the Windows 3.11 array.

It is important to note, for the sake of this question, that I do not use the browser section.

The first question, and rightfully so, posed what what is the value in $regex. However, I am still unable to find a way to get that value.

What I originally tried was declaring a global variable outside the function, and right before the preg_match line setting the global variable equal to regex. I then attempted to echo the global variable. I was greeted with a blank page.

I should also mention that I had (at the time of asking the original question) removed this code:

$user_agent     =   getBrowserOS();
$device_details =   "<strong>Browser: </strong>".$user_agent['browser']."<br />    <strong>Operating System: </strong>".$user_agent['os_platform']."";
print_r($device_details);
echo("<br /><br /><br />".$_SERVER['HTTP_USER_AGENT']."");

And thus the only thing I should have seen was the value of the global variable. Instead, I saw nothing.

Can someone explain how this should have been debugged?

Edit: As Per John C’s Answer

<?php
$user_agent     =   $_SERVER['HTTP_USER_AGENT'];
function getOS() { 
global $user_agent;
$os_platform    =   "Unknown OS Platform";
$os_array       =   array(
                        '/windows nt 6.2/i'     =>  'Windows 8',
                        '/windows nt 6.1/i'     =>  'Windows 7',
                        '/windows nt 6.0/i'     =>  'Windows Vista',
                        '/windows nt 5.2/i'     =>  'Windows Server 2003/XP x64',
                        '/windows nt 5.1/i'     =>  'Windows XP',
                        '/windows xp/i'         =>  'Windows XP',
                        '/windows nt 5.0/i'     =>  'Windows 2000',
                        '/windows me/i'         =>  'Windows ME',
                        '/win98/i'              =>  'Windows 98',
                        '/win95/'               =>  'Windows 95',
                        '/win16'                =>  'Windows 3.11',
                        '/macintosh|mac os x/i' =>  'Mac OS X',
                        '/mac_powerpc/i'        =>  'Mac OS 9',
                        '/linux/i'              =>  'Linux',
                        '/ubuntu/i'             =>  'Ubuntu',
                        '/iphone/i'             =>  'iPhone',
                        '/ipod/i'               =>  'iPod',
                        '/ipad/i'               =>  'iPad',
                        '/android/i'            =>  'Android',
                        '/blackberry/i'         =>  'BlackBerry',
                        '/webos/i'              =>  'Mobile'
                    );

foreach ($os_array as $regex => $value) { 
var_dump($regex);
var_dump($value);
    if (preg_match($regex, $user_agent)) {
        $os_platform    =   $value;
    }

}   
return $os_platform;
}
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T00:04:54+00:00Added an answer on June 7, 2026 at 12:04 am

    I’ll try to focus on this instance rather than general debugging, since I’m sure there are better guides to get you started.

    1. Look at the error message.
    Most of the time, PHP isn’t too bad at telling you what went wrong and where (within a couple of lines anway). In this instance, the you would have something along the lines of

    Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /var/www/html/whatever.php on line 36
    

    So the problem is a missing slash on line 36. Line 36 ( which falls within getOS()):

    if (preg_match($regex, $user_agent)) {
    

    We can infer this is a problem with $regex – in this instance a quick look at the array in question shows a missing / in one of the lines, but maybe the data is in a database or can’t be so easily checked.

    2. Start dumping variables
    If something isn’t right, checking in your variables is good start. You want to do this as close as possible to your error so you know nothing is happening in between. We know the problem is $regex from the above, so immediately above the problem line:

    var_dump($regex);
    if (preg_match($regex, $user_agent)) {
    

    New result:

    ...
    string '/win95/' (length=7)
    string '/win16' (length=6)
    
    Warning: preg_match() [function.preg-match]: No ending delimiter '/' found in /var/www/html/whatever.php on line 36
    

    PHP halts as soon as we get the error, so the last dumped line will show the problem variable. Hello, a regex with a missing slash!

    On your approach:
    PHP will halt when it hits an error, which is part of why I suggest dumping variables as close to the problem as possible. In your case, the script never got as far as your echo statements.

    Bonus notes!

    • I prefer var_dump() for checking variables because it is better at showing an empty/null variable (echo will just print a blank) plus it handles arrays and objects.
    • If you find yourself doing a lot of debugging, have a look at getting XDebug running. Immensely useful.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First of all: This question is not directly programming related. However, the problem only
This question may not directly relate to programming. I have noticed that the technology
This question is more a re-insurance than one directly about how to code. As
This is directly related to this question I finally figured out that Rails 3.0.6
This question is not directly programming related but I need my Server to pass
Sorry, this may or may not be a programming question directly, but I am
This very well my be a SuperUser.com question, however it's directly related to my
Disclaimer: this question is directly related to my programming homework. My C++ assignment consists
This question is related to a iOS project written in ObjectiveC that makes use
This may sound as a non related coding question but it's directly related :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.