1
我需要一些字符串进行排序,并与联系配合他们,这是我做的:在函数中对字符串排序是我的逻辑错误还是?
$name_link = $dom->find('div[class=link] strong');
返回数组[0] - [5]包含字符串,如NowDownload.eu
$code_link = $dom->find('div[class=link] code');
返回与0-5中的名称相匹配的链接,如链接[0]属于名称[0]
我不知道它们返回的顺序NowDownload.Eu可能是$ code_link [4]或$ code_link [3],但名称数组将按顺序匹配它。
现在,我需要$ code_link [4] //可以说,它的NowDownload.Eu成为$ LINK1每次
,所以我这样做
$i = 0;
while (!empty($code_link[$i]))
SortLinks($name_link, $code_link, $i); // pass all links and names to function, and counter
$i++;
}
function SortLinks($name_link, $code_link, &$i) { // counter is passed by reference since it has to increase after the function
$string = $name_link[$i]->plaintext; // name_link is saved as string
$string = serialize($string); // They are returned in a odd format, not searcheble unless i serialize
if (strpos($string, 'NowDownload.eu')) { // if string contains NowDownload.eu
$link1 = $code_link[$i]->plaintext;
$link1 = html_entity_decode($link1);
return $link1; // return link1
}
elseif (strpos($string, 'Fileswap')) {
$link2 = $code_link[$i]->plaintext;
$link2 = html_entity_decode($link2);
return $link2;
}
elseif (strpos($string, 'Mirrorcreator')) {
$link3 = $code_link[$i]->plaintext;
$link3 = html_entity_decode($link3);
return $link3;
}
elseif (strpos($string, 'Uploaded')) {
$link4 = $code_link[$i]->plaintext;
$link4 = html_entity_decode($link4);
return $link4;
}
elseif (strpos($string, 'Ziddu')) {
$link5 = $code_link[$i]->plaintext;
$link5 = html_entity_decode($link5);
return $link5;
}
elseif (strpos($string, 'ZippyShare')) {
$link6 = $code_link[$i]->plaintext;
$link6 = html_entity_decode($link6);
return $link6;
}
}
echo $link1 . '<br>';
echo $link2 . '<br>';
echo $link3 . '<br>';
echo $link4 . '<br>';
echo $link5 . '<br>';
echo $link6 . '<br>';
die();
我知道他们所找到的链接,我之前已经测试过,但是我想把它变成一个函数,并且它搞砸了,是我的逻辑错误,还是我通过变量/ ararys的方式存在问题?
我仍然不清楚这个问题。您能否向我们展示您在典型数组中的数据,以及您希望如何分类这些数据? – 2013-03-17 17:27:49
$ name_link [0]可能包含'NowDownload.eu' $ code_link [0]将包含属于'Nowdownload.eu'的链接 但是,它不是证明NowDownload.eu在$ name_link [0 ]它可能在$ name_link [4]中,但是$ code_link [4]仍然是属于$ name_link [4]的链接 而带有字符串NowDownload.eu的$ code_link必须变成$ link1 – 2013-03-17 17:30:37
那是否有什么意义? – 2013-03-17 17:31:05