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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:46:03+00:00 2026-05-24T23:46:03+00:00

Is preq_match supposed to return true for testing nothing on something? $needle = ;

  • 0

Is preq_match supposed to return true for testing nothing on something?

$needle = ""; 
$haystack = "test";
$result = preg_match("/" . $needle . "/i", $haystack);

I would expect $result to be 0, but it’s 1.

Logically speaking, testing nothing on something should yield nothing … how does the song go? Nothing from something leaves nothing … got to have something … if you want to be with me!.

I didn’t want to have to pretest to make sure nothing was something before I tested nothing against something :-). Hmm … I don’t think I could be more confusing if I tried.

  • 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-24T23:46:04+00:00Added an answer on May 24, 2026 at 11:46 pm

    There are actually several nothings in the string "test". They are (at a minimum, see my aside below):

    <nothing>t<nothing>e<nothing>s<nothing>t<nothing>
    

    That’s why you’re getting 1 as a result, it’s finding that first nothing before the t.

    And I suspect that either you’re misremembering that song or the bod who wrote it was not an engineer. Nothing from something leaves something (assumng we’re talking subtractive operations here).

    If it was “something from nothing leaves nothing”, that would make more sense but, being the anal-retentive personality type I am, I would have to insist that you can’t get something from nothing 🙂


    As an aside, I’d be interested in what preg_match_all returned for that. Some may think it’s 5 (and I suspect it is) but some may argue, from a purely theoretical viewpoint, that there are an infinite number of nothings at each of those points in the string. I would hope the developers of PHP were more practical than that.

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

Sidebar

Related Questions

I keep getting this error: Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on
I have used this pregmatch statement for validating email address preg_match(^[a-z0-9_\+-]+(\.[a-z0-9_\+-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*\.([a-z]{2,4})$^, $partner_email) If i
I know this is a very stupid question to ask but i have a
How do i preg_match an string to match the following format in php: $m=123/456789/01;
I assume this should be fine bool prefMatch = false; // Is the frequency
I'm having trouble reversing my doublely linked deque list (with only a back sentinel)
Trying to do basic SSL-authenticated Web Service using Visual Studio 2008 .NET 3.5 Service
I'm implementing a script that adds images to a page from a folder. The
I have a list of items that are in this format: 05/01 – Some
I've been beating around on this thing all day and it's driving me nuts!

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.