当我们在textarea中粘贴代码时,是否有像ckeditor这样的脚本删除样式和脚本? [关闭]

问题描述:

Is there any script like ckeditor that removes css and script when we paste code in a textarea? I want to remove css and script when user copy text from some where else and pastes it in my website

当我们将代码粘贴到一个脚本中时,是否有像 ckeditor strong>这样的脚本删除css和脚本 textarea的? 当用户从其他地方复制文本并将其粘贴到我的网站时,我想删除css和脚本 p> div>

$myHtml = // here is your html;
$doc = new DOMDocument();
$doc->loadHTML($myHtml);

removeElementsByTagName('script', $doc);
removeElementsByTagName('style', $doc);

$html = $doc->saveHtml();

function removeElementsByTagName($tagName, $document) {
  $nodeList = $document->getElementsByTagName($tagName);
  for ($nodeIdx = $nodeList->length; --$nodeIdx >= 0; ) {
    $node = $nodeList->item($nodeIdx);
    $node->parentNode->removeChild($node);
  }
}

(code from: https://stackoverflow.com/a/20082963/610573)