首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何隐藏XML中的特定元素?

如何隐藏XML中的特定元素?
EN

Stack Overflow用户
提问于 2020-02-23 07:03:04
回答 1查看 40关注 0票数 2

我的代码:

代码语言:javascript
运行
复制
$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显示元素的标题和描述,任何帮助都是非常感谢的!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-23 07:54:11

看这里:

代码语言:javascript
运行
复制
  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

代码语言:javascript
运行
复制
$feedToArray[base64_encode($f->description)] = json_encode($f);

和json_decode:

代码语言:javascript
运行
复制
 $f = json_decode($hash); // <-- decode hash and use to echo.
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60357672

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档