$pattern=Array();
$pattern[0] = "<a(\\s+(title=(\\"[^\\"]*\\")|href=(\\"[^\\"]*\\")|\\w+=(\\"[^\\"]*\\"|\\S+)))+>";
$pattern[1] = "#<a.*>(.+)</a#Ui"; //preg_match pattern in a for loop to get the href, title and innerhtml and exclude the book title in brackets
preg_match_all($pattern[0], $file, $file_1);
for($i=0; $i<count($file_1[4]); $i++){
$href=str_replace("\\"", "", $file_1[4]);
}
for($i=0; $i<count($file_1[3]); $i++){
$title=str_replace(" ", "", str_replace("\\"", "", $file_1[3]));
}
preg_match_all($pattern[1], $file, $file_2);
print_r($file_2[1]);
for($i=0; $i<count($file_2[1]); $i++){
$heb=explode(")", $file_2[1][$i]);
}
//var_dump($heb);
I realize that I don’t need to declare $heb as an array $heb=Array(); but I need to gather $file_2[1][$i][1] into one array. How would that be possible?
$file_link = "http://wlc.hebrewtanakh.com/sidemenu.htm";
$file = file_get_contents($file_link);
$pattern=Array();
$pattern[0] = "<a(\\s+(title=(\\"[^\\"]*\\")|href=(\\"[^\\"]*\\")|\\w+=(\\"[^\\"]*\\"|\\S+)))+>";
$pattern[1] = "#<a.*>(.+)</a#Ui"; //preg_match pattern in a for loop to get the href, title and innerhtml and exclude the book title in brackets
preg_match_all($pattern[0], $file, $file_1);
for($i=0; $i<count($file_1[4]); $i++){
$href=str_replace(" ", "", str_replace("\\"/", "", $file_1[4]));
}
for($i=0; $i<count($file_1[3]); $i++){
$title=str_replace(" ", "", str_replace("\\"", "", $file_1[3]));
}
preg_match_all($pattern[1], $file, $file_2);
$heb=Array();
for($i=0; $i<count($file_2[1]); $i++){
$heb=explode(")", $file_2[1][$i]);
$heb_title[]=$heb[1];
}
print_r($heb_title);
the url shows a menu of links. So I’m taking the links and putting it in arrays of href, title and innerhtml. The innerhtml has to be split where there is a “)”.
But the two loops I mentioned do the str_replace operation each time to the entire array, not only to the element you’re looping through. Are you sure the first loop shouldn’t be
$file_link = "http://wlc.hebrewtanakh.com/sidemenu.htm";
$file = file_get_contents($file_link);
$pattern=Array();
$pattern[0] = "<a(\\s+(title=(\\"[^\\"]*\\")|href=(\\"[^\\"]*\\")|\\w+=(\\"[^\\"]*\\"|\\S+)))+>";
$pattern[1] = "#<a.*>(.+)</a#Ui"; //preg_match pattern in a for loop to get the href, title and innerhtml and exclude the book title in brackets
preg_match_all($pattern[0], $file, $file_1);
for($i=0; $i<count($file_1[4]); $i++){
$href=str_replace("\ ", "", str_replace("\\"", "", str_replace("\\"/", "", $file_1[4])));
}
print_r($href);
for($i=0; $i<count($file_1[3]); $i++){
$title=str_replace(" ", "", str_replace("\\"", "", $file_1[3]));
}
print_r($title);
preg_match_all($pattern[1], $file, $file_2);
$heb=Array();
for($i=0; $i<count($file_2[1]); $i++){
$heb=explode(")", $file_2[1][$i]);
$heb_title[]=$heb[1];
}
print_r($heb_title);
the url shows a menu of links. So I’m taking the links and putting it in arrays of href, title and innerhtml. The innerhtml has to be split where there is a “)”.