2017-02-16 11 views
0

私はcurently PHPプログラムを開発していますが、私は問題があります: 私は文字列を持っており、その一部を抽出したいと思います。だから私は正規表現を使用しようとするが、明らかにdoesnt仕事。 コード:正規表現の構文

<?php 
    preg_match_all ('#>+.+Direction+(.)+-+.+/th>#i', $chaine_de_caractere, $direction); ?> 

文字列の一部。

<th scope="row" class="direction-name"> Direction BLABLA1 - BLABLA2 </th> 
<td class="departure-time"> 
    <span>15h30</span> 
</td> 

"BLABLA1"を保存したいだけです。 どこにエラーがありますか? を読み取るための おかげであなたはここでは、このregex

/>\s*Direction\s*(.*?)\s*-/

+0

あなたがしようとしている何取得する? – Kumar

+0

これを使うこともできます - > \> \ s?方向(。*)\ - ここに例があります---> https://regex101.com/r/mRpbPX/1 – Kumar

答えて

1

を持っている...

<?php 
$direction=preg_match('#direction-name">\s*Direction\s*(.+)?\s*-\s.*?<*#i', 
$chaine_de_caractere,$direction)?$direction[1]:'unknown'; 
echo $direction; 
+0

ありがとうございます:) –

0

があなたの質問に1行の答えは使用することができます素敵な一日