Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

206
Views
How to check if more than one space or beginning has space in PHP
  1. Hello World
  2. Hello World
  3. hello world

    or if the very beginning has space
  4. Hello World

It works if $q has normal values but I am getting $q value from search input and so it does not work except case 1.

$q = Input::get('q');

if(preg_match("/^\s+/", $q) || preg_match("/\s{2,}/", $q)) {
        echo 'Found Spaces';    
}
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Instead of Input::get('q'); use $q = $_GET['q'];
So your code becomes:

   $q = $_GET['q'];
    
    if(preg_match("/^\s+/", $q) || preg_match("/\s{2,}/", $q)) {
            echo 'Found Spaces';    
    }
over 4 years ago · Santiago Trujillo Report

0

if(preg_match("/^\s+/", $q) || preg_match("/\s{2,}/", $q))
    {
       
    }
 
over 4 years ago · Santiago Trujillo Report

0

/\s+/g
  • \s to match space.
  • + to said at least one.
  • g globally tag, all matches.
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!