I\'m using PHP\'s preg_match_all() to search a string imported using file_get_contents(). The regex returns matches but I would like to know at which line number those matches a
well it's kinda late, maybe you alrady solved this, but i had to do it and it's fairly simple.
using PREG_OFFSET_CAPTURE
flag in preg_match
will return the character position of the match.
lets assume $charpos, so
list($before) = str_split($content, $charpos); // fetches all the text before the match
$line_number = strlen($before) - strlen(str_replace("\n", "", $before)) + 1;
voilá!