2012-08-02 82 views
-1

獲取數據我有我的表列信息正則表達式從陣列

array('Email: Customer One <[email protected]>. By employee: [email protected]', 
    'By employee: [email protected] Department Head: Nickolas Jim.', 
    'Email: Customer One <[email protected]>. Status: currently employees.', 
    'Email: Customer One <[email protected]>. By employee: [email protected]' 
) 

等以下數據等

我有一個需要得到「通過員工從陣列中。換句話說,我需要正則表達式解決方案

ED。我只是需要通過員工如果present..nothing其他 所以在上面的例子中,我將有

By employee: [email protected] 
By employee: [email protected] 
By employee: [email protected] 

回答

1

我已經在PHP 5.4.5測試下面的示例代碼:

<?php 
$foo = array('Email: Customer One <[email protected]>. By employee: [email protected]', 
       'By employee: [email protected] Department Head: Nickolas Jim.', 
       'Email: Customer One <[email protected]>. Status: currently employees.', 
       'Email: Customer One <[email protected]>. By employee: [email protected]' 
      ); 

for($i = 0; $i < count($foo); ++$i){ 
    if(0 >= preg_match('/\bBy employee: ([-\w._][email protected][-\w]+(?:\.[-\w]+)*\.\w{2,4})\b/', $foo[$i], $matches)) 
     continue; 

    echo $matches[0] . "\n"; 
    echo $matches[1] . "\n"; 
    echo "\n"; 
}    

?> 

輸出:

 By employee: [email protected] 
[email protected] 

By employee: [email protected] 
[email protected] 

By employee: [email protected] 
[email protected] 
+0

你的解決方案給了我很多額外的東西 – Autolycus 2012-08-02 01:37:27

+0

所有我需要的是員工.. – Autolycus 2012-08-02 01:38:00

+0

好的,我看到你的最新修改。在這裏你是:) – godspeedlee 2012-08-02 01:47:47