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.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 04-09-2007, 03:47 AM   #1
Donners
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.
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 03:56 AM   #2
Calvinguy
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.
Calvinguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 04:00 AM   #3
schneemann
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
schneemann is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 04:02 AM   #4
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
Quote:
Originally Posted by Calvinguy View Post
There are several options. The 'file' function might be a good option for you.
I'm not good with php at all, could you explain a little more?
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 04:04 AM   #5
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
Quote:
Originally Posted by schneemann View Post
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.
I have a html file with 74 sections in it and want to include each section in its own page.

So 74 pages will take information from a single html page instead of taking it from 74 other pages.
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 04:43 AM   #6
Calvinguy
Confirmed User
 
Join Date: Oct 2002
Location: European Union
Posts: 1,752
Quote:
Originally Posted by Donners View Post
I'm not good with php at all, could you explain a little more?

$lines = file('yourfile.html');
echo $lines[1]; // will print line two from your included file
Calvinguy is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 05:04 AM   #7
schneemann
Confirmed User
 
Join Date: Oct 2006
Posts: 749
Quote:
Originally Posted by Donners View Post
I have a html file with 74 sections in it and want to include each section in its own page.

So 74 pages will take information from a single html page instead of taking it from 74 other pages.
Maybe I'm having a hard time visualizing what you're after.
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
schneemann is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 05:20 AM   #8
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
Quote:
Originally Posted by Calvinguy View Post
$lines = file('yourfile.html');
echo $lines[1]; // will print line two from your included file
Almost what Im looking for, but instead of choosing the lines I would like to choose a section (with multiple lines) from the included file.

Like a link anchor that defines a section of a page. And I want to include the anchor section.
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 05:39 AM   #9
joehoya
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>.
joehoya is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 05:54 AM   #10
Donners
Confirmed User
 
Join Date: Jun 2004
Posts: 689
Quote:
Originally Posted by joehoya View Post
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>.

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]);
?>
But it doesnt work, any ideas?
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-09-2007, 06:30 AM   #11
Donners
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;

?>
Thanks for the help.
Donners is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 04-11-2007, 12:16 PM   #12
joehoya
Registered User
 
Join Date: Feb 2006
Posts: 82
Any Time!
joehoya is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.