English 中文(简体)
载有超文本标签的案文的限量投入长度
原标题:Limit input length of text that contains HTML tags

我在“威治一”中设有一个网站,可以管理文章。 在添加新的条款表格时,我只想限制特性投入。 我在服务器边使用strlen(<<><>>><><><>方法进行核对。

问题在于<条码>。 看来,提供数目太大。 我尝试使用html_entity_decode( 文件<>,使html的标签摆脱了扼杀,但所造成的扼杀时间似乎是错误的。

最佳回答

html_entity_decode only decodes HTML entities, it doesn t ignore HTML tags. Try:

strlen(strip_tags(html_entity_decode($string)));

或多面当量:

mb_strlen(strip_tags(html_entity_decode($string)),  auto );
问题回答

你们想要获得一些特性,但你不想计算超文本标记。

您可以通过使用超文本格式,如。 页: 1

$doc = new DOMDocument();
$doc->loadHTMLFile( test.html );
$body = $doc->getElementsByTagName( body )->item(0);
$text = $body->nodeValue;
$text = trim(preg_replace( /s{1,}/u ,    , $text));
printf("Length: %d character(s).
", mb_strlen($text,  utf-8 ));

例输入<代码>test.html:

<body>
    <div style= float:left ><img src= ../../../../includes/ph1.jpg ></div>

    <label style= width: 476px; height: 40px; position: absolute;top:100px; left: 40px; z-index: 2; background-color: rgb(255, 255, 255);; background-color: transparent  >
    <font size="4">1a. Nice to meet you!</font>
    </label>
    <img src= ENG_L1_C1_P0_1.jpg  style= width: 700px; height: 540px; position: absolute;top:140px; left: 40px; z-index: 1;  />

    <script type= text/javascript > 


    swfobject.registerObject( FlashID );
    </script>

    <input type="image" id="nextPageBtn" src="../../../../includes/ph4.gif" style="position: absolute; top: 40px; left: 795px; ">

</body>

例产出:

Length: 58 character(s).

正常案文是:

1a. Nice to meet you! swfobject.registerObject( FlashID );

注意,案文的大小包括以下文字:<代码><script>tags。





相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签