首页 \ 问答 \ 删除所有html标签和限制字母php(delete all html tag and limit letters php)

删除所有html标签和限制字母php(delete all html tag and limit letters php)

我已经制作了这个PHP脚本:

//save the data into a variable
$testo = $news['testo'];

//delete all tag html
$testo = strip_tags($testo);

?>
<?php print "<p>".substr($testo,0,400)."...</p>"; ?>

首先我拿变量,然后删除所有标签并将字母限制为400。

但是有一个问题,这些字母与文章和文章不同。 喜欢:393封信,378封信,ecc。

我该怎么解决? 我希望每篇文章都有相同数量的字母。


i have made this php script:

//save the data into a variable
$testo = $news['testo'];

//delete all tag html
$testo = strip_tags($testo);

?>
<?php print "<p>".substr($testo,0,400)."...</p>"; ?>

First i take the variable and after i delete all tag and limit the letters to 400.

But there is a problem, the letters are different from article and article. Like: 393 letter, 378 letter, ecc.

how can I fix it ? I want the same number of letter for every article.


原文:https://stackoverflow.com/questions/35510674
更新时间:2022-02-25 17:02

最满意答案

Cookie只是一种在每个客户端或在会话层上方的客户端层存储信息的机制。 一般来说,人们讨厌cookie,因为他们可以做些令人毛骨悚然的东西,有些网站正在使用PC上的资源。

当你说我想存储一个我从不想读的cookie时,它真的很阴暗。 没有浏览器应该允许这种cookie。 您可能想重新查看一下您的架构。

但也许我不知道你究竟是什么意思。


Cookie is just a mechanism to store information at per client basis or in client layer above the session layer. In general people hate cookies cause they can do creepy stuff and some website is using resources on their PC.

When you say I want to store a cookie that I never want to read, its really shady. No browser should allow this sort of cookie. You might want to re-look at your architecture.

But may be I donno what exactly you mean.

相关问答

更多
  • 会话数据在SessionMiddleware的process_response中的Cookie中设置。 此函数不使用任何设置或request.user ,因此您无法在此方法内知道用户是登录用户还是匿名用户。 所以,你不能禁用发送会话cookie到浏览器。 但是,如果你想要这个功能,那么你可以SessionMiddleware并覆盖process_response 。 from django.contrib.sessions.middleware import SessionMiddleware from d ...
  • 请尝试以下代码
  • 您应该查看chrome.cookies API 。 具体来说,您可以连接到chrome.cookies.onChanged事件并相应地对每个添加的cookie做出反应。 还有一个API可以简单地禁用cookie,可能是每个域: chrome.contentSettings API 。 通常适用:如果您不熟悉Chrome扩展程序,请通读概述 。 另请参阅“ 样本”页面 。 You should look into the chrome.cookies API. Specifically, you can ho ...
  • 您需要调用非托管的InternetSetCookie()函数。 看! 有人已经为你写了互操作 。 你应该验证它的正确性。 You need to call the unmanaged InternetSetCookie() function. And look! Someone wrote the interop for you already. You should verify its correctness though.
  • 好的,我找到了一个解决方案。 如果将此行添加到Startup.cs中的ConfigureServices中,将永远不会创建cookie:services.AddAntiforgery(options => {options.Cookie.Expiration = TimeSpan.Zero;}); OK, I found a solution. If you add this line to ConfigureServices in Startup.cs the cookie will never be c ...
  • AFAIK,没有标准的方法。 但我认为容器确实提供了基于cookie关闭会话跟踪的选项。 例如, 这篇文章提到了一个似乎打开cookie进行会话跟踪的属性。 同样, Tomcat在其Context.xml文件或服务器xml文件中允许 “cookies = true”。 AFAIK, there is no standard way of doing this. But I think containers do provide an option of turning off session trackin ...
  • 大多数第三方身份验证提供程序都需要cookie才能正常工作。 例如,某些auth提供商(如live.com)会在用户访问登录页面之前生成初始Cookie。 单击登录按钮时需要这些cookie。 这个问题本身就是静音,但有趣的是,为什么电子不会让用户能够禁用/启用cookie,因为它只是具有该功能的铬的外壳。 也许用例不高。 Most of the third party auth providers require cookies to work correctly. For example, some a ...
  • 如果您关注GDPR合规性,那么仅删除cookie是不够的。 您需要禁用任何收集个人身份信息(PII)的跟踪脚本。 我建议将所有跟踪脚本移至Google Tag Manger,并使用Simo Ahava概述的方法。 指南1和指南2 。 他的方法不适用于跟踪非Google的标签,但使用自定义触发器可以阻止任何操作。 话虽这么说,如果你只是想删除cookie,这应该这样做。 function deleteCookies() { var theCookies = document.cookie.split( ...
  • Cookie只是一种在每个客户端或在会话层上方的客户端层存储信息的机制。 一般来说,人们讨厌cookie,因为他们可以做些令人毛骨悚然的东西,有些网站正在使用PC上的资源。 当你说我想存储一个我从不想读的cookie时,它真的很阴暗。 没有浏览器应该允许这种cookie。 您可能想重新查看一下您的架构。 但也许我不知道你究竟是什么意思。 Cookie is just a mechanism to store information at per client basis or in client layer ...
  • 许多站点在没有cookie开销的情况下用于提供静态资源的方式是使用不同的域。 例如,对于Stack Overflow,该域名为http://sstatic.net 在Web应用程序中,您可以将cookie限制为特定路径。 默认情况下,它们将被限制在设置它们的目录中。 您还可以使用setcookie()的$path参数显式指定它。 The way that many sites use to serve their static resources without the cookie overhead is ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)