Get line number of nth occurrence of string using php


I have a webapp which uses text files in order to achieve some CMS-like functionality.
However, I'd like to use a single file for multiple types of content.
Here is my file:



I want to get the line number of that line using php, where <--TYPEA--> occurs for the nth time (assuming that <!--TYPEA--> does not occur multiple times in a single line).
Example: $n=3 and $string="<!--TYPEA-->"
Result: line number of <!--TYPEA--><div>still html</div>



You can read the file line by line and test on each line if the string you are looking for is found by the nth time. A way to do that is:



Use it like this:






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

The Dalles, Oregon

眉山市

清晰法令