Php 正则表达式、数组到字符串的转换
我试图使用以下正则表达式从WHOIS结果中解析出唯一的姓名和电子邮件地址,这些正则表达式将所需的数据输出到数组中。我想将这些数组转换成字符串,并将它们放入mysql数据库。我的数据库很简单,包含名字、姓氏和电子邮件字段。我想知道我可以在这里使用哪些php函数。我欢迎你的建议Php 正则表达式、数组到字符串的转换,php,mysql,regex,Php,Mysql,Regex,我试图使用以下正则表达式从WHOIS结果中解析出唯一的姓名和电子邮件地址,这些正则表达式将所需的数据输出到数组中。我想将这些数组转换成字符串,并将它们放入mysql数据库。我的数据库很简单,包含名字、姓氏和电子邮件字段。我想知道我可以在这里使用哪些php函数。我欢迎你的建议 if (preg_match_all('/^registrant name: (.*)/im', $data, $matches)) // Print the matches:
if (preg_match_all('/^registrant name: (.*)/im', $data, $matches))
// Print the matches:
{
echo '<pre>' . print_r($matches, 1) . '</pre>';
} else {
echo 'not found!</p>';
}
if (preg_match_all('/^registrant email: (.*)/im', $data, $email))
// Print the matches:
{
echo '<pre>' . print_r($email, 1) . '</pre>';
} else {
echo 'not found!</p>';
}
为了简洁起见,可以修改正则表达式代码,因为当前代码会两次输出名称和电子邮件地址。有WHOIS API可以为您提供更干净的数据。$matches是一个二维数组-您只需要从中访问匹配的元素。例如:$registrant_name=$matches[0][1];。达贡,你能把它们贴在这里吗?我可以,或者你可以直接问谷歌。
Array
(
[0] => Array
(
[0] => Registrant Name: Dns Admin
[1] => Dns Admin
)
)
Array
(
[0] => Array
(
[0] => Registrant Email: dns-admin@google.com
[1] => dns-admin@google.com
)
)