Created
July 1, 2021 07:36
-
-
Save recca0120/8a89a280cd637d7095db2c950817d0eb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
function getContents($params) | |
{ | |
[$self, $file, $startLine, $startColumn, $endLine, $endColumn] = $params; | |
--$startLine; | |
--$startColumn; | |
--$endLine; | |
--$endColumn; | |
$handle = fopen($file, 'rb'); | |
$i = -1; | |
$content = ''; | |
while (($line = fgets($handle)) !== false) { | |
$i++; | |
if ($i < $startLine) { | |
continue; | |
} | |
if ($i === $startLine && $i === $endLine) { | |
$content .= substr($line, $startColumn, $endColumn - $startColumn); | |
break; | |
} | |
if ($i === $startLine) { | |
$content .= substr($line, $startColumn); | |
} else if ($i === $endLine) { | |
$content .= substr($line, 0, $endColumn); | |
break; | |
} else { | |
$content .= $line; | |
} | |
} | |
fclose($handle); | |
return $content; | |
} | |
echo var_export(json_decode(getContents($_SERVER['argv']), true), true).';'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment