如何测试 HTML 正文是否包含空标签 [英] How to test if a HTML body contains empty tags

查看:23
本文介绍了如何测试 HTML 正文是否包含空标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在某些表单字段上使用文本编辑器,TinyMCE.它工作正常.

I am using a text editor on certain form fields, TinyMCE. it works ok.

但是 TinyMCE 编辑器会为表单中的每个字段返回一个 HTML 正文标记.如果用户完成该表单字段,这完全没问题,即;

However the TinyMCE editor returns a HTML body tag for each field in the form. This is perfectly fine if a user completes that form field, i.e;

'description' => string '<!DOCTYPE html>
    <html>
    <head>
    </head>
    <body>
    a users response
    </body>
    </html>'

但是,如果用户没有完成该字段,TinyMCE STILL 将返回一个包含空 html 正文的字符串,即以下代码:

However, if a user does not complete the field TinyMCE STILL returns a string containing an empty html body, i.e the code below:

 'description' => string '<!DOCTYPE html>
<html>
<head>
</head>
<body>

</body>
</html>'

我想要做的是测试这个返回的表单字段"是否只包含空的 HTML 字段,即 html 字段的正文中没有值.

What I want to do is to test if this returned 'form field' contains just empty HTML field, i.e no values within the body of the html field.

总而言之,我如何测试上面的代码是否只包含空的 body 标签?

In summary how can I test that the above code just contains empty body tags?

推荐答案

它不是一个非常优雅的解决方案,但它有效.我只是使用 strip_tag() 从文档中删除标签,然后测试变量是否为空.如果它不为空,我提交 post 变量.

its not a very ellegant solution but it works. i simply remove the tags from the document using the strip_tag(), then test if the variable is empty. If its not empty i submit the post variable.

if (isset($_POST['description']))
                {
                    $preValidated = dsf_db_prepare_input($_POST['description']);
                    $testValue  = trim(strip_tags($preValidated));

                    if(!strlen($testValue) >= 1)
                    {
                        $description ='';
                     }
                     else
                     {
                        $description ="$preValidated";
                     }     
                }

这篇关于如何测试 HTML 正文是否包含空标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆