title: Search for part of a string in array
body: <p>i have been over so many posts online trying to sort this....</p>
  
  <p>i am integrating a small search feature into a php script....</p>
  
  <p>i have tried many scripts including <code>in_array</code> (only works for full match) and <code>array_search</code> </p>
  
  <p>and nothing seems to work....</p>
  
  <p>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....</p>
  
  <p>all filenames are seperated word by word with a <code>-</code></p>
  
  <p>all words have the first letter capital....</p>
  
  <p>the array is called <code>$files1</code>;</p>
  
  <p>the search string is called <code>$search_string</code>;</p>
  
  <p>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 <code>$search_results</code></p>
  
  <p>as the next part of my script to paginate needs the array <code>$search_results</code> to echo each of the filenames and display them 10 per page....</p>
  
  <p>hope this is enough info, ive been workin on it for ages and racking my brains trying to find the correct code....</p>
  
  <p>thanks in advance</p>
  
  <p>..........
  ...........</p>
  
  <p>EDIT.....</p>
  
  <p>.......
  ........</p>
  
  <p>got script working with preg_grep..... but i now have a slight problem....</p>
  
  <p>the script before the search code is designed to get the url of the search page with q={search string}</p>
  
  <p>and then trim this so that i just have the serach string as a variable.....</p>
  
  <p>i use an str_replace to change the page url from</p>
  
  <pre><code>/games-search?q={search-string}
  </code></pre>
  
  <p>to {search-string}</p>
  
  <p>this is perfectly fine, but the script to paginate the results as 10 per page adds ?page=2 to the url....</p>
  
  <p>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 </p>
  
  <pre><code>/games-search?page=2&amp;q={search-string}
  </code></pre>
  
  <p>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.....</p>
  
  <p>the page numbers vary from 1 - about 50 (never more than 99, so 2 digits would be enough to match....</p>
  
  <p>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.....</p>
  
  <p>here is my latest effort....</p>
  
  <pre><code>/games-search?page=(^[0-9][0-9]+)&amp;
  </code></pre>
  
  <p>that is what i am trying to replace with "" (eg, nothing)</p>
  
  <p>as i only need the data from after the &amp; character in the url ... and thats IF the url even contains this (for exapmple the first page when the url doesnt contain the &amp; character - if the url doesnt contain the &amp; character , i dont want it modifying as i already have the data i need)</p>
  
  <p>thanks again if anyone can help</p>
  
  <p></p>
  
  <p>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 :)</p>