GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   PHP question (https://gfy.com/showthread.php?t=722438)

Donners 04-09-2007 03:47 AM

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.

Calvinguy 04-09-2007 03:56 AM

There are several options. The 'file' function might be a good option for you.

schneemann 04-09-2007 04:00 AM

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.

Donners 04-09-2007 04:02 AM

Quote:

Originally Posted by Calvinguy (Post 12224302)
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 04-09-2007 04:04 AM

Quote:

Originally Posted by schneemann (Post 12224314)
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.

Calvinguy 04-09-2007 04:43 AM

Quote:

Originally Posted by Donners (Post 12224318)
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

schneemann 04-09-2007 05:04 AM

Quote:

Originally Posted by Donners (Post 12224325)
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.

Donners 04-09-2007 05:20 AM

Quote:

Originally Posted by Calvinguy (Post 12224451)
$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.

joehoya 04-09-2007 05:39 AM

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>.

Donners 04-09-2007 05:54 AM

Quote:

Originally Posted by joehoya (Post 12224602)
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 04-09-2007 06:30 AM

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.

joehoya 04-11-2007 12:16 PM

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