Results 1 to 2 of 2

Thread: Searching a string for substring that is in an array.

  1. #1
    Join Date
    May 2007

    Searching a string for substring that is in an array.

    Basically I have an array of small strings. Then I have a larger string in which I want to see if any of those in the array of smaller strings match anything in the larger string. Is there a function in php in which I can pass the array of smaller strings and the larger string and get a bool value or something like that? Or am I going to have to loop through each array index and do a preg_match on each to get a result? It doesn't matter which smaller string matches? Baiscally I want to see if any of the smaller strings match or if none match the larger one.

    Any advice is appreciated. Thanks in advance.

  2. #2
    Join Date
    Jun 2003
    preg_match does not support array searching, so you will have to loop, something like this should be sufficient:
    PHP Code:
    function preg_Amatch($pattern$string){
    $pattern as $tmp){
    If you are using PHP please use the [PHP] and [/PHP] forum tags for highlighting...
    The same applies to HTML and the forums [HTML][/HTML] tags.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center