【发布时间】:2021-01-31 17:50:44
【问题描述】:
我已经在我的数据库中创建了数据。它由ckeditor5制成。看起来像这里
数据提到了许多标签和属性。所以...我只需要在标签 p 中获取单词。所以我可以在我的网站上显示。结果示例如下:
注意:我只需要显示 100 个字母。并在最后一句中添加“...”。
我最后的代码是这样的:
function removeTags(str) {
if ((str === null) || (str === ''))
return false;
else
str = str.toString();
// Regular expression to identify HTML tags in
// the input string. Replacing the identified
// HTML tag with a null string.
return str.replace(/(<([^>]+)>)/ig, '');
}
<?php
while ($row = $result->fetch_array(MYSQLI_ASSOC)){
echo '
<script>
document.write(removeTags(
'.$row['main_article'].'));
</script>';
}
?>
【问题讨论】:
标签: javascript php html mysql ckeditor