-1
私は秩序を保つ、別の文字列の言葉と文字列を一致させたい正規表現:私は結果がPHP、するpreg_match特定の単語0または1時間
$result = array(0 => 'three', 1 => 'two', 2 => 'one');
になりたい
$string_original = "Number three is good, then two and one.";
$match_string = "three two one";
$result = magic_function($string_original,$match_string);
一致文字列内のすべての単語は、元の順序で検索されるためです。 他の例:
$string_original = "two is a magic number, one also and three";
$match_string = "three two one";
$result = magic_function($string_original,$match_string);
//RESULT WOULD BE
$result = array(0 => 'three');
//LAST EXAMPLE
$string_original = "three one, then two!";
$match_string = "three two one";
$result = magic_function($string_original,$match_string);
//RESULT WOULD BE
$result = array(0 => 'three', 1 => 'two');
マイmagic_functionは、正規表現の部分と任意の助け
function magic_function($origin,$match){
$exploded = explode(' ',$match);
$pattern = '/';
foreach ($exploded as $word){
$pattern .= '';//I NEED SOMETHING TO PUT HERE, BUT MY REGEX IS PRETTY BAD AND I DON'T KNOW
}
$pattern .= '/';
preg_match($pattern,$origin,$matches);
return $matches;
}
のようなものでしょうか?ありがとうございました。
私たちはあなたのコードを書いてください。 –
@ダゴン私はコード全体を書いた、私は理解できない正規表現で助けが必要です。それは簡単な要求であり、スクリプト全体ではありません... –
それは簡単です。 –