Skip to content

Instantly share code, notes, and snippets.

@picasso250
Created February 23, 2018 07:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save picasso250/3cccb88fcaee85aa3e95cbf52ee2aee0 to your computer and use it in GitHub Desktop.
Save picasso250/3cccb88fcaee85aa3e95cbf52ee2aee0 to your computer and use it in GitHub Desktop.
get first line of file content
<?php
function get_first_line($content) {
$pos = -1;
do {
$pos = strpos($content, "\n", $pos+1);
$found = trim(substr($content, 0, $pos));
// http://blog.sina.com.cn/s/blog_49f914ab0101eyjj.html
} while (trim(substr($content, 0, $pos), "\r\n\t \xEF\xBB\xBF") === "");
return substr($content, 0, $pos);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment