【问题标题】:explode function from a form field来自表单域的分解功能
【发布时间】:2014-02-26 07:50:24
【问题描述】:

我有一个 HTML 表单,要求用户粘贴一些代码:

<!-- Facebook Badge START -->

<a href="https://www.facebook.com/alex.gk" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="Alex Gk">Alex Gk</a>

<span style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; line-height: 16px; font-variant: normal; font-style: normal; font-weight: normal; color: #555555; text-decoration:none;">&nbsp;|&nbsp;</span>

<a href="https://www.facebook.com/badges/" target="_TOP" style="font-family: &quot;lucida grande&quot;,tahoma,verdana,arial,sans-serif; font-size: 11px; font-variant: normal; font-style: normal; font-weight: normal; color: #3B5998; text-decoration: none;" title="&#x394;&#3b7;&#x3bc;&#x3b9;&#x3bf;&#x3c5;&#x3c1;&#x3b3;&#x3ae;&#x3c3;&#x3c4;&#x3b5; &#x3c4;&#x3bf; &#x3b4;&#x3b9;&#x3ba;&#x3cc; &#x3c3;&#x3b1;&#x3c2; &#x3b4;&#x3b9;&#x3b1;&#x3ba;&#x3c1;&#x3b9;&#x3c4;&#x3b9;&#x3ba;&#x3cc;!">Δημιουργήστε το δικό σας διακριτικό</a><br/>

<a href="https://www.facebook.com/alex.gk" target="_TOP" title="Alex G">
    <img src="https://badge.facebook.com/badge/1565383.3437.1745257502.png" style="border:0px;" />
</a>

 <!-- Facebook Badge END -->

我想要在 PHP 中只保留以下部分,以便用户粘贴整个代码 但提交表单后,它只保留以下部分。

<a href="https://www.facebook.com/alex.gk" target="_TOP" title="AlexG">
    <img src="https://badge.facebook.com/badge/1383.3437.1745257502.png" style="border:0px;" />
</a>

【问题讨论】:

  • 您可以使用explode() 并返回数组,但是如果您知道Alex Gk 中的第一个词或发送词是否为粗体| Δημιουργήστε το δικό σας διακριτικό 你可以像 $str = 'Alex Gk | Δημιουργήστε το δικό σας διακριτικό'; $arr = explode("|",$str);现在 $arr[0] 和 $arr[1] 将包含字符串,如果您知道哪个是粗体,您可以使用该数组索引。
  • 我在发布的代码中没有看到任何 bold 部分。如果粗体部分来自您的用户,为什么不发布相关代码。
  • 这个粘贴的 html 总是这样构造吗?如果是这样,您可以使用类似 domdocument 加载 html 函数并始终抓住第三个锚点。 php.net/manual/en/domdocument.loadhtml.php

标签: php forms text explode


【解决方案1】:

你试过strip_tags()吗?

$text = strip_tags($text, '&lt;b&gt;&lt;strong');

【讨论】:

  • 感谢您的回答。我想要的是只保留这部分:facebook.com/alex.gk" target="_TOP" title="Alex Gk"> badge.facebook.com/badge/1505265383.3437.1745257502.png" style="border:0px;" /> 这不是粗体。我的错误
猜你喜欢
  • 1970-01-01
  • 2013-12-01
  • 2010-12-04
  • 2012-12-24
  • 1970-01-01
  • 2016-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多