【问题标题】:Get all words from string until certain word从字符串中获取所有单词直到某个单词
【发布时间】:2011-11-02 11:03:53
【问题描述】:
$title = 'the.test.hd.part12';

需要所有单词直到找到单词“part”

应该返回 - the.test.hd.

任何帮助表示赞赏。谢谢。

【问题讨论】:

  • 你看过 trim(); ?

标签: php string text-extraction


【解决方案1】:

echo strstr($title, 'part', true); // As of PHP 5.3.0

【讨论】:

    【解决方案2】:
    echo current(explode('part12',$title));
    

    【讨论】:

      【解决方案3】:

      对于 PHP 版本

      echo substr($title, 0, strpos($title, $needle));

      【讨论】:

        猜你喜欢
        • 2012-03-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多