在 tinymce 文本编辑器数据中的字符串末尾附加一个句点/点


Append a period/dot at the end of the string in a tinymce text editor data

目前我的数据保存在mysql数据库中,如下所示。我需要在字符串末尾附加一个句点或点,同时以 html 显示数据。下面是示例。

存储在数据库中的数据

<strong>Hello World </strong>
当字符串不以句点或

感叹号或问号结尾时,我需要在字符串末尾添加句点。

当我像上面提到的在字符串末尾附加一个句点时,它会在 HTML 中显示"Hello World "。一个空格出现在一个单词"世界"和一个句点之间。我需要通过删除 HTML 标签来删除该空间。

我的PHP代码在字符串末尾附加一个句点。当没有 HTML 标签或字符串不以 HTML 标签结尾时,它可以完美地工作

$val = "<strong>Hello World </strong>";
$string_to_replace = array("<br />","&nbsp;","&nbsp; ");
$val = str_replace("''r''n",' ', $val );
$val = trim(stripslashes($val));
$val = trim(str_replace($string_to_replace,'', $val ));
$val_without_tag = trim(strip_tags($val));
$val_without_tag = str_replace($string_to_replace,'', $val_without_tag );
$last_val = substr($val_without_tag,-1);
$regularexp = array('.','!','?');
if(!empty($last_val)){
   if(in_Array($last_val, $regularexp)){
        return $val;
    }
    else {
    return $val.". ";
    }
}

我的两分钱,虽然它可能不漂亮。

我会向后搜索"<"。如果找到,请检查里面的内容是否是单词(而不是另一个标签)。如果它是一个单词,请将句点放在找到"<"的位置 -1(如果在 pos 123 找到,则句点为 122)。

一旦我靠近计算机,我会尝试为此上传一些代码。