views:

59

answers:

3

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

A: 

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

valexa
+2  A: 
$res = str_replace(
    array('  ','   ',PHP_EOL,"\n","\r\n"),
    array('','','','',''),
    $res);

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.

preg_match_all("#\<tr class\=\"phead\"\>\<td colspan\=\"2\"\>(.+)\<\/tr\>(.+)\<div class\=\"first\"\>\<\/div\>\<div\>\<\/div\>(.+)\<\/div\>#U",$res,$bulk);

means the developer had no clue that HTML should not be parsed with Regex.

Gordon
A: 
$res=$this->post("http://address.mail.yahoo.com/?_src=&amp;VPC=print",$post_elements);
$emailA=array();

-> post data to http://address.mail.yahoo.com/?_src=&amp;VPC=print and get the response, assign to $res

$res=str_replace(array('  ','   ',PHP_EOL,"\n","\r\n"),array('','','','',''),$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

Bang Dao