Home » questions » PHP: How can I echo ONLY some part of a text file?

PHP: How can I echo ONLY some part of a text file?

2006-08-13 00:36:59, Category: Programming & Design
For example there is a file called "hello.txt" which contains: Hello, how are you? this is a book Now I want to echo the part which is between and that is "this is a book" How can I do it?

Answers

  1. boukenger

    On 2006-08-13 00:42:55


    First, read the contents of the file into a string variable with file_get_contents(). Call this variable $text. Then use the following code: $start = strpos($text, ""); $end = strpos($text, ""); echo substr($text, $start, ($end - $start))); This should output the text between the two tags.