我的代码:
$title = 'example';
foreach(Feed('http://example.com') as $f ) {
if (strpos($f->title, $title) !== false) {
$feedToArray[] = base64_encode(json_encode($f)); // <------ hash result in new array
}
}
foreach(Feed('http://example2.com') as $f ) {
if (strpos($f->title, $title) !== false) {
$feedToArray[base64_encode($f->description)] = base64_encode(json_encode($f));
}
}
$newArray = array_unique($feedToArray); // <--- remove duplicated hashed results
// loop new array
foreach($newArray as $hash ) {
$f = json_decode(base64_decode($hash)); // <-- decode hash and use to echo.
if (strpos($f->title, $title) !== false)
echo "<span style='font-weight: 600;'>". $f->title.":". "</span>". "<br>". $f->description. "<br>";
}我不想显示一些输出,因为它与我无关的信息。基本上,我不想用example123显示元素的标题和描述,任何帮助都是非常感谢的!
发布于 2020-02-23 07:54:11
看这里:
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=601') as $f ) {
if (strpos($f->title, $title) !== false) {
if ($f->title !== 'Ev 134 Oslofjordtunnelen, på strekningen Drammen - Vassum (Viken)') {
$feedToArray[base64_encode($f->description)] = base64_encode(json_encode($f)); // <------ hash result in new array
}
}
}
foreach(Feed('https://www.vegvesen.no/trafikk/xml/savedsearch.rss?id=604') as $f ) {
if (strpos($f->title, $title) !== false) {
if ($f->title !== 'Ev 134 Oslofjordtunnelen, på strekningen Drammen - Vassum (Viken)') {
$feedToArray[base64_encode($f->description)] = base64_encode(json_encode($f)); // <------ hash result in new array
}
}
}
//$newArray = array_unique($feedToArray); // <--- remove duplicated hashed results
// loop $feedToArray <------------------------
foreach($feedToArray as $hash ) {
$f = json_decode(base64_decode($hash)); // <-- decode hash and use to echo.
echo "<span style='font-weight: 600;'>". $f->title.":". "</span>". "<br>". $f->description. "<br>";
}编辑:
Try:对于数组值,只能使用json_encode
$feedToArray[base64_encode($f->description)] = json_encode($f);和json_decode:
$f = json_decode($hash); // <-- decode hash and use to echo.https://stackoverflow.com/questions/60357672
复制相似问题