将功能从php转换为javascript

时间:2019-05-20 15:09:07

标签: javascript php

我在PHP中有一个函数,该函数从tinymce获取内容,然后解码HTML元素,然后从第一个单词中获取10个单词。这样做的目的是向用户仅显示部分内容。

以下是函数:

 function getPartialContent($content, $words_number = 10 )
  {
      $no_tags_content = preg_replace("/\r|\n/", "", html_entity_decode(filter_var($content, FILTER_SANITIZE_STRING)));

      $words = explode(" ", $no_tags_content);
      $result = implode(" ", array_splice($words, 0, $words_number));
      return $result;
  }

如何在javascript中具有此功能?我知道如何将长字符串拼接成单词并获取所需的单词数。但是我不知道该怎么做:

 $no_tags_content = preg_replace("/\r|\n/", "", html_entity_decode(filter_var($content, FILTER_SANITIZE_STRING)));

由于内容是由tinymce制作的并且包含HTML标记,因此需要首先获取html_entity_decode(filter_var(

或者在JavaScript中有更好的方法吗?

0 个答案:

没有答案
相关问题