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

  • Home
  • SEARCH
  • 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 4549916
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:25:34+00:00 2026-05-21T16:25:34+00:00

The problem: Let’s say I have $keyword = a sentence entered into a search

  • 0

The problem:

Let’s say I have $keyword = a sentence entered into a search box, such as “large white boxes”

What I need to do is break this into individual words, and then test each word to make sure a * doesn’t appear within the first 3 letters. (So, sen* would be ok, but se* would NOT be ok). If a * does appear in first 3 letters of any individual word, then the “if ($keyword) …” process needs to end.

if ($keyword)  {


            $token = strtok($keyword, " ");
                while ($token != false) {
                    echo $token;
                        if (stripos($token,"*") < 3 ) {
                        return;
                        }
                    $token = strtok(" ");
                    }

…code continues…

As you can see, I am echoing each time to see it processing.

If I get rid of the ‘if’ code, then it outputs ‘largewhiteboxes’ and continues on as expected.

If I leave the ‘if’ code as-is, only ‘large’ is output, and the routine ends – even though the condition has not been met!

If I run that ‘if’ statement on its own, outside of the WHILE loop, it works just fine, responding true to a * in first 3 positions, and false for everything else…

What might I be doing wrong with this???

  • 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-05-21T16:25:34+00:00Added an answer on May 21, 2026 at 4:25 pm

    This variation seems to work.

    $keyword = "large white boxes";
    
    $token = strtok($keyword, " ");
    
    while ($token !== false) {
        echo $token;
        $pos = stripos($token, "*");
        if ($pos < 3 && $pos !== false) {
            return;
        }
        $token = strtok(" ");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The problem: let's say I have two tables Client , and Product , in
The underlying problem - let's say my documents have categories and timestamps . If
Consider this problem: I have a program which should fetch (let's say) 100 records
My problem is simple. I search a specific pattern in a file (let's say
I am stuck with following monad problem: Let's say I have a standard monad
so I have a problem: Let's say I have Messages and Users and the
I would like to have some suggestions for the following problem: Let's say you
I have a question on making a good subquery for this problem Let's say
I have the following problem to solve: Let's say there is a table A
Here's my problem: Let's say I have these tables: table1 1 - a 2

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.