【问题标题】:Ignore data within a certain set of characters with PHP使用 PHP 忽略特定字符集中的数据
【发布时间】:2009-11-11 19:27:55
【问题描述】:

不知道这叫什么,但有没有办法可以从文件中提取数据,回显它,但忽略特定字符集中的数据?

<?php
echo file_get_contents('test.txt');
?>

当我回显最终函数时,是否可以忽略星号之间的数据以及星号本身?

【问题讨论】:

    标签: php function preg-match echo file-get-contents


    【解决方案1】:

    你不会像“什么都没有”那样“忽略它”

    一种快速的“n”脏方法

    echo preg_replace( "/\*{3}.*?\*{3}/", "", file_get_contents( 'test.txt' ) );
    

    【讨论】:

    • 工作完美。现在有了它,我可以尝试其他字符串了。
    • 请注意,这个正则表达式是“贪婪的”,所以“this *** some text *** is a *** other text *** test”会变成“this test”,而不是您可能期望的“这是一个测试”。
    • 不,不是。我特意故意让子模式变得不贪婪。而且我相信您打算指示的测试字符串是"this *** some text *** is a *** other text *** test"
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-21
    • 1970-01-01
    • 2022-01-22
    • 2015-09-10
    • 2018-09-27
    • 2021-11-18
    相关资源
    最近更新 更多