2012-06-23 61 views
0

我有一個我通過表單提交的textarea。PHP從textarea列表中刪除不需要的字符

然後我從它那裏得到的文本:

$textArea = $_POST['my_textarea']; 

$textArea's content is this: 

myemail1.com=somethinge 
myemail2.com=somethingelse 
myemail3.com=somethingel 

我的問題是,我需要等號(=)後起飛的所有字符。

所以,一旦做了它應該是這樣的:

myemail1.com 
myemail2.com 
myemail3.com 

任何想法?

+0

http://php.net/manual/en/function.explode.php –

+0

是每封郵件摹保證以新的路線分開? –

回答

1
$emails = array(); 

$temp = explode("\r\n", $_POST['my_textarea']); 
foreach ($temp as $line) 
{ 
    $tmp = explode("=", $line); 
    $emails[] = $tmp[0]; 
} 

print_r($emails); 
1

如果電子郵件是每個對自己的各條線,這preg_replace函數應該去除所有多餘的給你:

$cleanEmails = preg_replace("/(\.[a-z]{2,4})=.*$/", "$1", $textArea); 
0

這裏是另一個方法:

$emails = array_keys(parse_ini_string($textarea));