Jump to content

preg-match Intermittantly Not Working


Excession

Recommended Posts

Hi Guys,

 

I'm hoping you can help with this one. My function intermittently works and then doesn't work. When I read one phrase from a text file, the application works. When I read 2 or more phrases, the function works for some of the phrases, but not others. So for example the function doesn't match Phrase 1,2 & 3, but matches phrase 4.

 

This is very puzzling. Not too sure if it is a bug in preg_match or problems with using large arrays or something else  8)

 

Your help will be greatly appreciated

 

Code:

 

Note: $sentences_func is an array of sentences which need to be matched and sorted into 2 arrays. One array is of sentences that contain the Phrase, and the other, sentences that don't contain the phrase.

 

 

function phrase_contained_sort($sentences_func,$file_value_func){

   // Array Tracking Variables for contains_keyword and not_contains_keyword Arrays
     $n1_pcs = 0;
     $n2_pcs = 0;  

   // Prepare REGEX to find Phrase in Sentence
     $phrase_match_func = "{".$file_value_func."}i"; 


   foreach ($sentences_func[0] as $sentences_value_func){
  
     // Remove Immediately Repeating Words from Sentences  
     $de_duplicate_value = de_duplicate_words($sentences_value_func);    
           
     // Test if Phrase is Present in Sentence
     $present_func = preg_match($phrase_match_func, $de_duplicate_value); 
  
     if ($present_func == 1){
    
      $contains_phrase_array_func[$n1_pcs]=$de_duplicate_value;
      $n1_pcs++;        
      }

     else{
    
      $not_contains_phrase_array_func[$n2_pcs]=$de_duplicate_value;
      $n2_pcs++;
      }
  }       
  
  return array($contains_phrase_array_func, $not_contains_phrase_array_func);
}

 

EDITED by akitchin: please use code tags.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.