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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:58:23+00:00 2026-05-29T09:58:23+00:00

i have been over so many posts online trying to sort this…. i am

  • 0

i have been over so many posts online trying to sort this….

i am integrating a small search feature into a php script….

i have tried many scripts including in_array (only works for full match) and array_search

and nothing seems to work….

i have a script that creates an array with file names (all in the format “Random-Name-1.ext”)
but the script removes the file extention, just leaving the filenames….

all filenames are seperated word by word with a -

all words have the first letter capital….

the array is called $files1;

the search string is called $search_string;

what im looking for would be along the lines of a foreach loop to check if the search string is contained in any part of each array value, and if it is, put the full array value into another array called $search_results

as the next part of my script to paginate needs the array $search_results to echo each of the filenames and display them 10 per page….

hope this is enough info, ive been workin on it for ages and racking my brains trying to find the correct code….

thanks in advance

……….
………..

EDIT…..

…….
……..

got script working with preg_grep….. but i now have a slight problem….

the script before the search code is designed to get the url of the search page with q={search string}

and then trim this so that i just have the serach string as a variable…..

i use an str_replace to change the page url from

/games-search?q={search-string}

to {search-string}

this is perfectly fine, but the script to paginate the results as 10 per page adds ?page=2 to the url….

so when i click page 2, the str_replace to change the url to search string doesnt work now, as the new page url for page 2 is

/games-search?page=2&q={search-string}

i have been trying to do another str_replace to change the consecutive pages urls to just the search string but i am having problems with the regex to define the page number…..

the page numbers vary from 1 – about 50 (never more than 99, so 2 digits would be enough to match….

i have tried over and over again today to get this regex correct but i am not sure if i am going about it the correct way…..

here is my latest effort….

/games-search?page=(^[0-9][0-9]+)&

that is what i am trying to replace with “” (eg, nothing)

as i only need the data from after the & character in the url … and thats IF the url even contains this (for exapmple the first page when the url doesnt contain the & character – if the url doesnt contain the & character , i dont want it modifying as i already have the data i need)

thanks again if anyone can help

decided not to paginate the results of each search as ther will never be more than about 15 results….. this is fine, but i am going to implement a miminum search length of 4 characters so it doesnt bring up 500 results for the letter A 🙂

  • 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-29T09:58:24+00:00Added an answer on May 29, 2026 at 9:58 am

    Search an array for a substring match? preg_grep

    Then do something like

    $search_results = ...;
    $paginated = array();
    for ($i = 0; $i < count($search_results); $i++)
    {
        if ($i % 10 == 0) $paginated[$i + 1] = array();
        $paginated[$i][] = $search_results[$i + 1];
    }
    

    Then print_r that array, and you’ll see you’ve got something dead easy to work with.

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

Sidebar

Related Questions

There are many usability evaluation techniques that have been developed over the history of
I have been puzzling over a problem this morning with LinqToSQL. I'll try and
I have been looking over the internet for a while about this, but it
I have been looking over this code for the past hour, I cant see
This is a bit of a vague notion which I have been running over
I have been search all over the net and couldn't find an appropriate solution
i have been getting into rails over the course of the last couple weeks
I've been trying to get this complex MYSQL query to work exactly right over
There have been many threads started over the confusion in the way that Math.Round
I have been reading over some code lately and came across some lines such

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.