Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get text from URL and store that to the array. And I have existing array. So, how can I compare that two array? I have tried this. But this coding is giving not match always.

What I have tried:

<?php
$url = 'http://www.test.oddly.co/robots.txt';
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, 1);
$result = curl_exec($curl);
curl_close($curl);
echo $result.'
';
$arr = array("kadirgamar","arrow","orion","woolimlanka","nippon","luna-tower","thotalagala","altair","arrowlibrary",
"ashraf","ashrafnew","invoke","lavana","leia","lorelle","lioc","liocdev","lorellenew","openmanthri","opentapes ","
rates","rsq","signature","site","visualretale","srhr","smitratest","smitra","lioccontent","lioccopy","liocold","
global","echelon","arrowlive"
);
$array = explode('Disallow: / ',$result);
unset($array[0]);
$array = array_values($array);
function trim_array_element(&$item1)
{
$item1 = preg_replace('/\//', '', $item1);
}
array_walk($array,'trim_array_element');
print_r($array).'
';
print_r($arr);
if($array === array_intersect($array, $arr) && $arr === array_intersect($arr, $array))
{
echo "Both arrays are equal.";
}
else
{
echo "Both arrays are different.";
}
?>
Posted
Updated 7-Dec-17 4:41am

1 solution

Likely owing to the remnant invisible leading or trailing white spaces left after the trim_array_element() function, try this:
trim(preg_replace('/\//', '', $item1));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900