![]() |
PHP question
Is there a way to use php include command to include only a part of a file?
For exampel if a html file has two lines in it LINE ONE LINE TWO I want to use php include to only include LINE TWO in my website. |
There are several options. The 'file' function might be a good option for you.
|
It depends on whether you it will only ever have two lines in it, or if you know exactly what that line contains. In any case, it sounds like a bit inefficient to be doing anything I can think of just to include one line of text from a two line file.
|
Quote:
|
Quote:
So 74 pages will take information from a single html page instead of taking it from 74 other pages. |
Quote:
$lines = file('yourfile.html'); echo $lines[1]; // will print line two from your included file |
Quote:
Here's what I think: Put it in a database. A database will be FAR faster. file() will read all 74 sections into memory at once whereas with a database you can grab the specific one you want. |
Quote:
Like a link anchor that defines a section of a page. And I want to include the anchor section. |
Quick answer is to modify your big html page so that each of the 74 sections is encased between a <div> tag. each <div> tag will include an id attribute (e.g. id="73") which will identify the section.
From here you could use the xml parser in php5 to build a solution that might last. If you just want something quick and dirty, assuming you aren't using <div> tags anywhere else in your big html file. you could write a regular expression that pulls all data beginning with <div id="73"> and ending with the first instance of </div>. |
Quote:
Thanks for the answer. I manage to pull this code together: Code:
<?php |
Sorted it out, this code worked for me.
Code:
<?php |
Any Time!
|
All times are GMT -7. The time now is 07:17 PM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123