String processing-how to remove intermediate strings in PHP

Source: Internet
Author: User
6691. club, registered, 2015-06-17T17: 15: 08Z, 2016-06-166688.club, registered, 2014-05-07T15: 02: 16Z, registered, 2015-06-10T06: 03: 05Z, 2016-06-096695.club, registered, 2015-06-10T14: 32: 14Z, 2016-06... 6691. club, registered, 2015-06-17T17: 15: 08Z, 2016-06-16
6688. club, registered, 2014-05-07T15: 02: 16Z, 2016-05-06
6689. club, registered, 2015-06-10T06: 03: 05Z
6695. club, registered, 2015-06-10T14: 32: 14Z
6694. club, registered, 2015-11-08T15: 01: 24Z, 2016-11-07
6693. club, registered, 2015-06-17T17: 20: 25Z
6692. club, registered,: 14: 43Z
6690. club, registered, 2015-06-22T08: 43: 14Z, 2016-06-21
6605. club, registered, 2015-06-25T08: 43: 19Z
6606. club, registered,: 56: 01Z
6603. club, registered, 2015-06-25T08: 43: 17Z
6604. club, registered, 2015-11-09T09: 13: 15Z, 2016-11-08
6681. club, registered, 2015-06-17T13: 44: 15Z
6608. club, registered, 2015-06-10T09: 27: 52Z
6607. club, registered, 2015-06-25T08: 43: 21Z
6682. club, registered,: 43: 28Z

In this case, I want to remove the section T15: 43: 28Z, starting with T and ending with Z.

I only have the PHP environment on my machine. I can see some East PHP. Other programs do not understand ............

Please advise me .......

Reply content:

6691. club, registered,: 15: 08Z
6688. club, registered, 2014-05-07T15: 02: 16Z, 2016-05-06
6689. club, registered, 2015-06-10T06: 03: 05Z
6695. club, registered, 2015-06-10T14: 32: 14Z
6694. club, registered, 2015-11-08T15: 01: 24Z, 2016-11-07
6693. club, registered, 2015-06-17T17: 20: 25Z
6692. club, registered,: 14: 43Z
6690. club, registered, 2015-06-22T08: 43: 14Z, 2016-06-21
6605. club, registered, 2015-06-25T08: 43: 19Z
6606. club, registered,: 56: 01Z
6603. club, registered, 2015-06-25T08: 43: 17Z
6604. club, registered, 2015-11-09T09: 13: 15Z, 2016-11-08
6681. club, registered, 2015-06-17T13: 44: 15Z
6608. club, registered, 2015-06-10T09: 27: 52Z
6607. club, registered, 2015-06-25T08: 43: 21Z
6682. club, registered,: 43: 28Z

In this case, I want to remove the section T15: 43: 28Z, starting with T and ending with Z.

I only have the PHP environment on my machine. I can see some East PHP. Other programs do not understand ............

Please advise me .......


  

You can use PHP to process small files. If the file is large, it is faster to use sed.
sed -i "s/T.*Z//g" test.txt

If regular expression matching is used, the registered user name may also contain TZ characters, so we can consider string truncation. After allT17:15:08Z,2016-06-16The length of this segment is fixed.

Use Regular Expressions

$ Subject = '2017. club, registered, 2015-06-17T17: 15: 08Z, 2016-06-16 '; $ pattern = '/(. *, [\ d] {4}-[\ d] {2}-[\ d] {2}) T [\ d:] {8} Z (, [\ d] {4}-[\ d] {2}-[\ d] {2} $)/'; preg_match ($ pattern, $ subject, $ matches ); print_r ($ matches);/* Array ([0] = & gt; 6691. club, registered, 2015-06-17T17: 15: 08Z, 2016-06-16 [1] => 6691. club, registered, [2] => )*/

$ Result = preg_replace ("/T \ d {2 }:\ d {2 }:\ d {2} Z/", "", $ str ); $ str is your text

Thank you. By studying the code above, I have learned and processed it myself:
The full-range code is as follows:


   \n";        echo preg_replace('/\w\d\d\:\d\d\:\d\d\w/',"",$buffer)."
\n"; } if (! feof ( $handle )) { echo "Error: unexpected fgets() fail\n" ; } fclose ( $handle );} ?>

Basically, I have achieved what I want. Thanks again for your help.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.