谁能解释一下 4 行 php 代码吗?我很困惑
code-
$res=$this->post("http://address.mail.yahoo.com/?_src=&VPC=print",$post_elements);
$emailA=array();
$bulk=array();
$res=str_replace(array(' ',' ',PHP_EOL,"\n","\r\n"),array('','','','',''),$res);
preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<div\>\<\/div\>(.+)\<\/div\>#U",$res,$bulk);
$post_element
是一个数组,我主要是consern ablut str_replace
和 preg_replace_all
函数行
code-
$res=$this->post("http://address.mail.yahoo.com/?_src=&VPC=print",$post_elements);
$emailA=array();
$bulk=array();
$res=str_replace(array(' ',' ',PHP_EOL,"\n","\r\n"),array('','','','',''),$res);
preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<div\>\<\/div\>(.+)\<\/div\>#U",$res,$bulk);
$post_element
is an array, I am mainly consern ablut str_replace
and preg_replace_all
function line
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
意思是:用第二个数组中的值替换第一个数组中的字符串,例如将两个空格变为空,将三个空格变为空,将平台相关的换行符变为空,将换行符变为空,将回车符后跟换行符什么都没有。
意味着开发人员不知道 HTML 不应使用正则表达式进行解析。
means: replace the strings in the first array with the values in the second array, e.g. turn two spaces into nothing, turn three spaces into nothing, turn the platform dependent newline character to nothing, turn newline character to nothing, turn carriagereturn followed by newline to nothing.
means the developer had no clue that HTML should not be parsed with Regex.
在该代码中,str_replace删除空格字符,并且preg_match_all通过正则表达式匹配html中的某些值,代码中没有preg_replace_all
in that code str_replace removes whitespace characters and preg_match_all matches by regex some values in the html, there is no preg_replace_all in the code
->将数据发布到
http://address.mail.yahoo.com/?_src=&VPC=print
并获取响应,分配给 $res-->删除任何 while-space、tab-space、end-line ...
并参考此处的最后一个
http://php.net/manual/en/function.preg-匹配所有.php
-> post data to
http://address.mail.yahoo.com/?_src=&VPC=print
and get the response, assign to $res--> delete any while-space, tab-space, end-line ...
and reference here for the last one
http://php.net/manual/en/function.preg-match-all.php