【问题标题】:Extract the name of the movie or TV serie提取电影或电视剧的名称
【发布时间】:2012-12-16 00:30:14
【问题描述】:

从该路径中提取电影或电视剧名称的最佳解决方案是什么? E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt?

我已经检查了explode,但如果您必须从路径中拆分每个/,那么该解决方案会很烦人。

编辑

搜索结果可能不止一次。结果可以这样显示:

E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt
E:\Dropbox\Hemsidor\collection-test\movies\the_butterfly_effect\documents\actors.txt

如何循环播放标题?

提前致谢。

【问题讨论】:

    标签: php extract


    【解决方案1】:
    $string = 'E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt?';
    
    preg_match('/\\\movies\\\([^\x5C]+)/', $string, $matchs);
    
    echo $matchs[1];
    

    【讨论】:

    • 成功了!非常感谢您提供了一个非常简单的解决方案 :) 我会尽可能接受。
    【解决方案2】:

    这个简单的搜索不需要正则表达式。事实上,RegEx 对于大规模数据来说速度较慢。 以下代码将完美完成

    $string = 'E:\Dropbox\Hemsidor\collection-test\movies\avatar\documents\actors.txt?';
    $a = explode('\\', $string);
    echo $a[array_search('movies', $a)+1];
    

    【讨论】:

    • 那个解决方案也很简单,如果不是更简单的话:P 非常感谢!
    • 嗯,RegEx 对于大规模数据来说速度较慢。
    • 确实如此。但是,如何使用您的解决方案提取多个标题?我忘了在我的问题中提到 ashamed 我不知道如何尽可能好地解释它,但是如果某个演员出现在多个标题中,则会出现更多路径。
    • @ErikEdgren for multiple string 在循环中使用它。
    • 谢谢 :) 我让它工作了。我会接受你的解决方案,因为它比 RegEx 更快。
    猜你喜欢
    • 2012-01-18
    • 1970-01-01
    • 2021-02-25
    • 2012-07-26
    • 2010-12-23
    • 2023-01-15
    • 2014-08-05
    • 1970-01-01
    • 2017-03-26
    相关资源
    最近更新 更多