所以我试图从字符串中获取最后一个字......
$pieces = explode(" ", $row["post_content"]);
print_r($pieces);
$customerEmail = array_pop($pieces);
echo "Email: " . $customerEmail."<br><br>";
$row["post_content"]
= I wish I could be the icing on the cake..whipped snapbac50@gmail
运行代码让我:
Array ( [0] => I [1] => wish [2] => I [3] => could [4] => be [5] => the [6] => icing [7] => on [8] => the [9] => cake..whipped snapbac50@gmail.com ) Email: cake..whipped snapbac50@gmail.com
我希望数组的结尾只回显电子邮件。如果我cake...whipped
,为什么它会在电子邮件之前包含array_pop()
?我只想要这封电子邮件。
答案 0 :(得分:1)
因为字符串包含空格以外的空格字符,所以您必须使用不同的函数:preg_split('/\s+/', $row['post_content']);
这将使用pcre正则表达式为一个或多个空白字符拆分字符串。