Pradeep
Pradeep

Reputation: 3

How would I detect the first X and next few characters from every line

I have a log file, it contains 1000 lines of log and I need to detect the first 22 characters and next 15 characters (25th to 40th) of every line. You would have a line like this:

    Dec 2, 2014, 11:23 PM - +91 90000 90000: lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum lorem ipsum

But it needs to like this

     Dec 2, 2014, 11:23 PM

and

     +91 90000 90000

Upvotes: 0

Views: 43

Answers (1)

Sadikhasan
Sadikhasan

Reputation: 18600

$handle = fopen("test.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
            echo $datetime= substr($line, 0, 22)."<br>";
            echo $mobile = substr($line, 24, 37)."<br>";
    }
    fclose($handle);
}

test.txt

Dec 2, 2014, 11:23 PM - +91 90000 90000:
Dec 4, 2015, 11:24 PM - +91 56569 85656:
Dec 25, 2015, 11:24 PM - +91 56569 85656:

Output

Dec 2, 2014, 11:23 PM
+91 90000 90000:
Dec 4, 2015, 11:24 PM
+91 56569 85656:
Dec 25, 2015, 11:24 PM
+91 56569 85656:

Upvotes: 1

Related Questions