Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:2072 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 37003 invoked by uid 1007); 28 May 2003 21:55:05 -0000 To: internals@lists.php.net Message-ID: <3ED5409A.2010802@whiffen.net> Date: Thu, 29 May 2003 02:04:58 +0300 Organization: Whiffen Net Ltd. User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02 X-Accept-Language: en-us, en MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Posted-By: 80.221.251.199 Subject: include() - partial includes? From: george@whiffen.net (George Whiffen) Apologies in advance if internals is not for feature requests. include() and require() pick up the whole file. Could we have the option to include just part of the file? Proposed new syntax for include(), require(): include ( string filename [, string start_tag [, string end_tag]]) If the optional start_tag is specified, the file is only read from immediately after the first occurrence of the start_tag string in the file. If the optional end_tag is also specified, reading of the file stops with the last character before the end_tag. Example: include('layout.html',"\n","\n

Some standard title

Some php output

Complaints to

would include only the header section, i.e.:

Some standard title

Purpose: At least for me, it is very common for at least the header and footer of every page to be prepared and maintained by an html developer as part of a "standard" layout. Individual php generated html pages "include" the header, then write their own output and finally "include" the footer. With the current include()/require(), the header and footer MUST be stored in individual files. They have to be "cut out" of the standard layout design page and stored in separate files e.g. header.txt and footer.txt. From then on, the html developer has to maintain them individually without the benefit of viewing them together in the layout page via their html editor. With partial includes available, the layout page could be used directly to provide the header, footer, navigation and any other standard includes while still being easily maintainable and viewable as a whole by non-php html developers using standard html editors. I believe this is a common scenario where partial includes would save time and significantly improve maintainability. There are plenty of other possible uses. It could just as well be mail text, xml, or plain old php code that you might prefer to handle in sections of one file rather than being forced into placing each section in a separate include files. Implementation: With the proposed syntax, implementation shouldn't be too bad. It's really just an extra couple of string scans i.e. the php equivalent would be something like: $code = get_file_contents($filename); $startpos = strpos($code,$start_tag); if ($startpos) { $startpos = $startpos + strlen($start_tag); $endpos = strpos($code,$end_tag,$startpos); if ($endpos) { $code = substr($code,$startpos,$endpos - $startpos); } else { $code = substr($code,$startpos); } } eval('?>'.$code.'