【问题标题】:PHP retrieve text value from custom tags with preg_matchPHP 使用 preg_match 从自定义标签中检索文本值
【发布时间】:2013-03-13 14:49:55
【问题描述】:

大家好,我已经在 php 网站上搜索了一个快速简单的解决方案,我也在 google 上搜索过,但没有找到可以工作的接缝。

preg_match("/\[video-code\](.*?)\[\/video-code\]/", the_content(), $match);
echo "result=".$match[1];

我正在尝试将这些文本之间的文本添加到标签“[video-code]...[/video-code]” 有没有人可以帮助我解决这个小问题?我尝试了不同的方法,但似乎我做错了什么!?

我们将不胜感激。

提前致谢。

【问题讨论】:

    标签: php preg-match custom-tag


    【解决方案1】:

    '¬\[BeginingOfTag](.*?)\[/EndOfTag]¬is'

    我在我的大多数网站上都使用了这种模式,我过去在 preg_match 中使用过它,但主要用于 preg_replace。所以试一试,让我知道它是否有效。

    【讨论】:

    • 当我尝试这个时,我在浏览器中收到这个错误,我将它与 wordpress 结合使用,也许这是个问题!? 警告 : preg_replace() [ function.preg-replace ]: /home/ 中的分隔符不能是字母数字或反斜杠test/domains/test.nl/public_html/test/wp-content/themes/test/overlay-samen-trots.php21
      result=
    • 好吧,我想通了,它与 Wordpress 有关。 Wordpress 'the_content()' 以某种方式格式化。它没有看到它,因为文本是我最好的猜测。因此,我现在使用 $post->post_content 而不是 'the_content()' 并且效果很好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-13
    • 2018-02-23
    • 1970-01-01
    相关资源
    最近更新 更多