protected function multi_explode(array $delimiters, $string) { if (defined('STRICT_TYPES') && CAMEL_CASE == '1') { return (array) self::parameters(['delimiters' => DT::TYPE_ARRAY, 'string' => DT::STRING])->call(__FUNCTION__)->with($delimiters, $string)->returning(DT::TYPE_ARRAY); } else { return (array) multi_explode($delimiters, $string); } }
function process_sentences($num_paragraph) { global $sentence_index; global $phrase_index; debug("Entered process_sentences with {$num_paragraph}\n"); //print_r($sentence_index); foreach ($sentence_index as $id => $sentence) { $phrases_array = multi_explode(array(',', " - ", " and ", " but "), $sentence['sentence_text']); $i = 0; foreach ($phrases_array as $phrase_text) { $row = array(); $row['phrase_text'] = trim(strtolower($phrase_text)); $row['phrase_num'] = $i; $row['paragraph_num'] = $sentence['paragraph_num']; $row['phrase_sentence'] = $sentence['sentence_text']; $i++; if ($phrase_text) { $phrase_index[] = $row; } } } $phrase_count = count($phrase_index); debug("Created {$phrase_count} phrases\n"); }
function multi_explode(array $delimiter, $string) { $d = array_shift($delimiter); if ($d != NULL) { $tmp = explode($d, $string); foreach ($tmp as $key => $o) { $out[$key] = multi_explode($delimiter, $o); } } else { return $string; } return $out; }