2016-11-08 6 views
1

私はこのサンプル文字列を持っています。phgを使用して文字列中の文字列を配列に分割する

$string = "There four of them. These are: 1 The first one. Its is the most common. 2 The second one. 3 The third one. 4 This is the last."; 

Iは上記$stringで与えられた情報を含む配列に分割したかったです。私はそれがこのように見えるようにしたい。

Array ( 
    [0] => The first one. Its is the most common. 
    [1] => The second one. 
    [2] => The third one. 
    [3] => This is the last. 
) 

私はそれを手伝ってもらえますか?ありがとうございました。

+0

の結果を参照してください。 –

+0

最初の配列には2つのドット(。)が含まれています。 – Jote

+0

このディスカッションを終了するには1つの答えを記入してください。 – Mohammad

答えて

3

次の例のように、整数で文字列を分割するpreg_splitを使用することができます。

$string = "There four of them. These are: 1 The first one. Its is the most common. 2 The second one. 3 The third one. 4 This is the last."; 

$matches = preg_split('/\d+/', $string); 

var_dump($matches); 
+0

ありがとうございます。出来た。文字数を数えます。しかし、私はユーザーprint_r()。ありがとう。 – Jote

+0

しかし、 '$ matches [0]'は追加です。 – Mohammad

1

あなたは、文字列のターゲット部分を選択するpreg_match_all()で正規表現を使用することができます。正規表現は2桁の文字列を選択します。

preg_match_all("/\d+([^\d]+)/", $string, $matches); 
print_r($matches[1]); 

(、$文字列を "")爆発demo

関連する問題