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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:29:36+00:00 2026-05-27T21:29:36+00:00

I got just a test pattern here, but it does disallow spaces. $myarray[]=’s s’;

  • 0

I got just a test pattern here, but it does disallow spaces.

$myarray[]='s s';
if (preg_match('/[^\d\w\(\)\[\]\.\-]+/',$myarray)>0) echo 'yes';

This does nothing, but

$test='s s';
if (preg_match('/[^\d\w\(\)\[\]\.\-]+/',$test)>0) echo 'yes';

This works fine…
I dont understand why it doesn’t work with my array?

  • 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-27T21:29:37+00:00Added an answer on May 27, 2026 at 9:29 pm

    preg_match doesn’t accept an array as input, just a single string. You’d need to do something like…

    $matched = no;
    foreach($myarray as $x) {
        if (preg_match('/[^\d\w\(\)\[\]\.\-]+/',$x)>0) $matched = true;
    }
    if($matched) echo 'yes';
    

    To do it in one step:

    function preg_match_any($regex,$array) {
        foreach($array as $x) {
            if (preg_match($regex,$x)>0) return true;
        }
        return false;
    }
    
    //Then to call it just something like:
    if (preg_match_any('/[^\d\w\(\)\[\]\.\-]+/',$myarray)) echo 'yes';
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just got this frame for a sudoku solver, but I don't understand the
I've created this just to test things outside my main program. I got this
Just got a question about generics, why doesn't this compile when using a generic
I just got this error message: ... from c:/ruby/lib/ruby/gems/1.8/gems/... ... 10 levels... from c:/ruby/lib/ruby/gems/1.8/gems/...
I was trying out Rails again, this time the 3 version, but I got
I just got this quite large CakePHP app (about 20k lines of code), which
just got a slight problem here with updating a MySql DataGridView from visual studio
I just got PHP's mail function to work properly in my test environment. I
I just got Delphi 2009 and have previously read some articles about modifications that
I just got a dedicated server from a hosting company, and for some reason,

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.