![]() |
![]() |
![]() |
||||
Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact us. |
![]() ![]() |
|
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed. |
|
Thread Tools |
![]() |
#1 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
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. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#2 |
Confirmed User
Join Date: Oct 2002
Location: European Union
Posts: 1,752
|
There are several options. The 'file' function might be a good option for you.
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#3 |
Confirmed User
Join Date: Oct 2006
Posts: 749
|
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.
__________________
Deranged World |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#4 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#5 | |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Quote:
So 74 pages will take information from a single html page instead of taking it from 74 other pages. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#6 |
Confirmed User
Join Date: Oct 2002
Location: European Union
Posts: 1,752
|
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#7 | |
Confirmed User
Join Date: Oct 2006
Posts: 749
|
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.
__________________
Deranged World |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#8 | |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Quote:
Like a link anchor that defines a section of a page. And I want to include the anchor section. |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#9 |
Registered User
Join Date: Feb 2006
Posts: 82
|
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>. |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#10 | |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Quote:
Thanks for the answer. I manage to pull this code together: Code:
<?php $start='<div id="73">'; $end='</div>'; $page='test2.html'; $fp=fopen($page,'r'); $cont=fread($fp,filesize($page)); preg_match("/$start(.*)$end/s",$cont,$match); $info=$match[0]; print($cont[1]); ?> |
|
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#11 |
Confirmed User
Join Date: Jun 2004
Posts: 689
|
Sorted it out, this code worked for me.
Code:
<?php $start='<!-- START HTML DATA -->'; $end='<!-- END HTML DATA -->'; $page='yay.html'; $fp=fopen($page,'r'); $cont=fread($fp,filesize($page)); preg_match("/$start(.*)$end/s",$cont,$match); $info=$match[0]; fclose($cont); print $info; ?> |
![]() |
![]() ![]() ![]() ![]() ![]() |
![]() |
#12 |
Registered User
Join Date: Feb 2006
Posts: 82
|
Any Time!
|
![]() |
![]() ![]() ![]() ![]() ![]() |