D
D
Dc8882015-09-12 14:07:50
JavaScript
Dc888, 2015-09-12 14:07:50

Json, json_encode + preg_replace how to implement?

The question is the following: when displaying the loaded information, let's say in the link to the picture in the news, extra characters are added - /\'/'
I try to do this but. but it doesn't work

$news[] = $data;
  $json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json);
  echo $json = json_encode($news);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dc888, 2015-09-12
@Dc888

If I understand you correctly, then there is such a piece of code, the load file itself is

if ($rows) {
    $result = dbquery(
      "SELECT tn.*, tc.*, tu.user_id, tu.user_name, tu.user_status
      FROM ".DB_NEWS." tn
      LEFT JOIN ".DB_USERS." tu ON tn.news_name=tu.user_id
      LEFT JOIN ".DB_NEWS_CATS." tc ON tn.news_cat=tc.news_cat_id
      WHERE ".groupaccess('news_visibility')." AND (news_start='0'||news_start<=".time().")
        AND (news_end='0'||news_end>=".time().") AND news_draft='0'
      GROUP BY news_datestamp DESC LIMIT ".$_GET['rowstart'].",".$items_per_page
    );
    $numrows = dbrows($result);
        while ($data = dbarray($result)) {
      $i++;
      $comments = dbcount("(comment_id)", DB_COMMENTS." WHERE comment_type='N' AND comment_hidden='0' AND comment_item_id='".$data['news_id']."'");
      $news_cat_image = "";
      $news_subject = "<a name='news_".$data['news_id']."' id='news_".$data['news_id']."'></a>".stripslashes($data['news_subject']);
      $news_cat_image = "<a href='".($settings['news_image_link'] == 0 ? "news_cats.php?cat_id=".$data['news_cat']
                                        : FUSION_SELF."?readmore=".$data['news_id'] )."'>";
      if ($data['news_image_t2'] && $settings['news_image_frontpage'] == 0) {
        $news_cat_image .= "<img src='".IMAGES_N_T.$data['news_image_t2']."' alt='".$data['news_subject']."' class='news-category' /></a>";
      } elseif ($data['news_cat_image']) {
        $news_cat_image .= "<img src='".get_image("nc_".$data['news_cat_name'])."' alt='".$data['news_cat_name']."' class='news-category' /></a>";
      } else {
        $news_cat_image = "";
      }
      $news_news = preg_replace("/<!?--\s*pagebreak\s*-->/i", "", ($data['news_breaks'] == "y" ? nl2br(stripslashes($data['news_news'])) : stripslashes($data['news_news'])));
      $news_info = array(
        "news_id" => $data['news_id'],
        "user_id" => $data['user_id'],
        "user_name" => $data['user_name'],
        "user_status" => $data['user_status'],
        "news_date" => $data['news_datestamp'],
        "cat_id" => $data['news_cat'],
        "cat_name" => $data['news_cat_name'],
        "cat_image" => $news_cat_image,
        "news_subject" => $data['news_subject'],
        "news_ext" => $data['news_extended'] ? "y" : "n",
        "news_reads" => $data['news_reads'],
        "news_comments" => $comments,
        "news_allow_comments" => $data['news_allow_comments'],
        "news_sticky" => $data['news_sticky']
      );

      $news[] = $data;
    $json = preg_replace("#(/\*([^*]|[\r\n]|(\*+([^*/]|[\r\n])))*\*+/)|([\s\t]//.*)|(^//.*)#", '', $json);				
    }
    echo $json = json_encode($news);
  }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question