【问题标题】:Get All Strings between tags and echo them? [duplicate]获取标签之间的所有字符串并回显它们? [复制]
【发布时间】:2011-11-23 19:51:33
【问题描述】:

可能重复:
Get content between two strings PHP

好的,这是我的定义:

这是我的 $content 示例:

<!--nextpage-->First Title Here<!--nexttitle-->

some more text here

and here and here and here

a little more here!

<!--nextpage-->Second Title Here<!--nexttitle-->

some more text here

and here and here and here

a little more here!

<!--nextpage-->Third Title Here<!--nexttitle-->

some more text here

and here and here and here

a little more here!

我如何运行一个函数来查找所有“get_all_strings_between()”并将它们回显到 $content 的顶部:

**First Title Here** / **Second Title Here** / **Third Title Here**

and then my content HERE!

谢谢!!

【问题讨论】:

    标签: php


    【解决方案1】:

    如果我正确理解了你的问题,这个正则表达式会做到:

    function get_all_strings_between($content) {
        preg_match_all('/<!--nextpage-->([^<]*)<!--nexttitle-->/', $content, $m);
    
        return implode(' / ', $m[1]);
    }
    
    // then you echo get_all_strings_between($content) where you need it
    

    如果我不正确,请提供更多信息这些nextpagenexttitle 标签是什么?字面意思是这样的吗?

    【讨论】:

    • 它们是 CMS 的一部分。只是数据库中的字符串。谢谢你的评论。我会试试看!!
    • 你明白了!哇,我对此进行了研究,而你的那一次是唯一对我有用的!!也许是因为我是个菜鸟,但非常感谢。这个功能的速度快吗??还是有更快的方法,我拥有的一些 $content 字符串非常大....??
    • 正则表达式不是最快的工具,但在你真正遇到问题之前不要考虑性能。尝试对大字符串运行它,看看会发生什么。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-10-05
    • 1970-01-01
    相关资源
    最近更新 更多