[英]Encoding input in textarea with javascript for TinyMCE editor
This is quite complicated. 这很复杂。 I'm not able to put this into words directly.
我无法直接将其表达出来。 So here goes my problem -
所以这是我的问题-
I've this short-code generator form built upon WordPress TinyMCE editor which is basically an HTML document. 我已经在WordPress TinyMCE编辑器上构建了此短代码生成器表单,该表单基本上是HTML文档。 It has two
<textarea></textarea>
inputs. 它有两个
<textarea></textarea>
输入。 When user clicks on "Insert short-code", javascript code on this page populates the short-code and inserts it into the editor in WordPress. 当用户单击“插入短代码”时,此页面上的javascript代码将填充该短代码并将其插入WordPress的编辑器中。
Now, if the user inserts something like - 现在,如果用户插入类似-
>>>This is an "amazing post"! You can't wait to get your hands on it.<<<
in the one of the textarea, the short-code generates the corresponding attribute as this - 在一个文本区域中,短代码生成相应的属性,如下所示:
c_text=">>>This is an "amazing post"! You can't wait to get your hands on it.<<<"
This short-code with other attributes is then saved into database by WordPress. 然后,具有其他属性的短代码将由WordPress保存到数据库中。 When it is retrieved at the front-end, the
add_shortcode()
function in WordPress messes everything up, which is quite obvious as >,<,',"
exist inside c_text
当在前端对其进行检索时,WordPress中的
add_shortcode()
函数将所有内容弄乱了,这很明显,因为c_text
存在>,<,',"
An obvious choice in PHP would be to use htmlentities
with ENT_QUOTES
, but how to do it in this case? PHP中的一个显而易见的选择是将
htmlentities
与ENT_QUOTES
一起使用,但是在这种情况下该如何做呢? Using the phpjs equivalent function would mean including lot of javascript. 使用phpjs等效功能意味着要包含很多JavaScript。 How to do this effectively?
如何有效地做到这一点?
UPDATE : I tried using the phpjs equivalent function. 更新 :我尝试使用phpjs等效功能。 It does the conversion properly.
它可以正确执行转换。 But, the quotes are replaced by WordPress.
但是,引号由WordPress代替。 Example - I put a random string
<> <test> <<><<<>><<> ' <"">?sdg#@Y^#ASCST#@Y^
示例-我放置了一个随机字符串
<> <test> <<><<<>><<> ' <"">?sdg#@Y^#ASCST#@Y^
and did console.log(htmlentities(string,'ENT_QUOTES'));
并做了
console.log(htmlentities(string,'ENT_QUOTES'));
, it logged ,它记录了
<> <test> <<><<<>><<> ' <"">?sdg#@Y^#ASCST#@Y^
which is correct. 哪个是对的。 But, when I viewed the switched to HTML view of TinyMCE, it showed
但是,当我查看TinyMCE的HTML切换视图时,它显示了
<> <test> <<><<<>><<> ' <"">?sdg#@Y^#ASCST#@Y^
The quotes were replaced by TinyMCE. 报价已由TinyMCE代替。
我最终使用了urlencode
函数,效果很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.