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 8912217
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:08:43+00:00 2026-06-15T04:08:43+00:00

So I am trying to check to see if this array has an underscore

  • 0

So I am trying to check to see if this array has an underscore in it. I am not sure if I am using the correct function to do this. Any input would be appreciated.

Some more info, if the array does have an underscore I want it to run the code below. This code seperates and gives me the attributes that I want. I also check if it has and S and then run some code. These are all output to queries which are then queried at the end.

    if (count($h)==3){
           if (strpos($h[2], '_') !== false)  // test to see if this is a weird quiestion ID with an underscore
               {
                    if (strpos($h[2], 'S') !== false)
                    {
                     // it has an S
                     $underscoreLocation = strpos($h[2], '_');
                     $parent = substr($h[2], 0, $underscoreLocation - 6); // start at beginning and go to S
                     $title = substr($h[2], $underscoreLocation - 5, 5);
                     $questions = "select question from lime_questions where sid =".$h[0]." and gid =".$h[1]." and parent_qid =".$parent." and title =".$title.";";
                    }
                    else
                    {
                     // there is no S
                     $underscoreLocation = strpos($h[2], '_');
                     $parent = substr($h[2], 0, $underscoreLocation - 2);
                     $title = substr($h[2], $underscoreLocation - 1, 1);
                     $questions = "select question from lime_questions where sid =".$h[0]." and gid =".$h[1]." and parent_qid =".$parent." and title =".$title.";";
                    }    
               }

           else
           {
            $questions = "select question from lime_questions where sid =".$h[0]." and gid =".$h[1]." and qid =".$h[2].";";
           }
  • 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-15T04:08:45+00:00Added an answer on June 15, 2026 at 4:08 am

    strpos() is a good function to use when checking to see if a substring exists within a string, so your basic premiss is fine.

    The haystack you’re submitting to the strpos() (i.e. $h[2]) is a string , isn’t it? You say in your question that you’re checking if an array contains an underscore, but the code only checks to see if a single array item contains an underscore – these are two very different things.

    If $h[2] is a sub array instead of just a string within the $h array then you need to iterate through the subarray and check each item.

    so:

      for ($x=0; $x<count($h[2]); $x++) {
         if (strpos($h[2][$x], "_")!==false) {
             if (strpos($h[2][$x], 'S') !== false) {
                // Run code
             } else { 
                // Run code
             }
         }
      }
    

    If $h[2] is just a string then what you have should be fine.


    Update: try adding

    print($h[2][$x].' - '.strpos($h[2][$x], ''));
    

    on the line before

    print ($h[2][$x].' - '.strpos($h[2][$x], '')); 
    

    This should give us an idea of what the problem is.


    Update:

    Based n the code we just ran things are very different from what I thought. First of all, not all of the $h arrays returned have 3 items. Secondly $h2 is a stirng, not a subarray.

    so here’s the new code:

      if (count($h)==3) {
         print($h2.' | ');
         if (strpos($h[2], "_")!==false) {
             print(' underscore was found | ');
             if (strpos($h[2], 'S') !== false) {
                // Run code
             } else { 
                // Run code
             }
         }
      } else {
         // array does not represent a question
      }
    

    Also, you need to change all of the $h[2][$x] back to just $h[2]. Tell me how it goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that I am trying to check wether or not an
I'm trying to check whether user has installed my application or not. The flow
I'm using get_results to get an array with data. Within this data has post
I have been trying to check my arraylist to see if an object already
I am trying to check a series of buttons to see if they have
I am trying to implement a check to see if the .NET framework is
I'm trying to check if a file exists. If I use this: NSData *data
I'm trying to check network available or not. But in my emulator it always
I'm trying to add random numbers onto the end of this array when ever
So I have this array list that is populated using a csv file. Once

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.