load info from text doc

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
vixtran
Forum Newbie
Posts: 5
Joined: Thu May 04, 2006 7:53 am

load info from text doc

Post by vixtran »

Hello all.. I was wondering if there was a way to load different paragraphs say 5 or 10 to different pages using a text document. I am pretty new to php and have read alot, but seem to be missing something. I can get the whole doc to load of course, but cant seem to get it to stop where I want. I am new and have been reading, but I missing something..

thanks in advance!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

code? example data? example output?
vixtran
Forum Newbie
Posts: 5
Joined: Thu May 04, 2006 7:53 am

Post by vixtran »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


sorry, I should have been more detailed.  I am using code I found on the net being that I am inexperienced

the code:

Code: Select all

$textfile= "../doc/info.txt";
$handle = fopen($textfile, "r");
$contents = fread($handle, filesize($textfile));
fclose($handle);

$content = explode("&noah=", $contents);
print($content[1]);
example data...

just plain text document with multiple paragraphs

for example:

case above:

&noah= blah blah approx 400 characters.

next paragraph

&sarah= blah blah approx 300 characters.

and about 10 paragraphs below

example output:

full paragraph displayed on data specific web page


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Play with the results from the following

Code: Select all

$output = preg_split('#\s*&([^=]+)=\s*#s', $contents, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
That should replace your explode() call. You will need to adjust the print() call too.
vixtran
Forum Newbie
Posts: 5
Joined: Thu May 04, 2006 7:53 am

Post by vixtran »

thanks again!

I am sorry.. I am new at this, but I dont see where I would call the specific paragraph to be displayed on the page I wanted it too... am I missing something?
vixtran
Forum Newbie
Posts: 5
Joined: Thu May 04, 2006 7:53 am

Post by vixtran »

ok I have played with it and reading and playing lol .. but to no avail. I can get it only to pull in the first paragraph no matter what I do. ( which isnt much with my abilities.) no matter what php page I put it in, only the first paragraph.. I have spent a better time of the morning reading about syntax.. what does the ' # ' mean in that string? I think I have pieced the meaning together.. if someone could put it in english maybe I could understand a little more?

thanks all
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Read our regex tutorials and the links I provide about regex in Useful Posts.
bbuttry
Forum Newbie
Posts: 2
Joined: Tue May 31, 2005 2:49 pm

Solution

Post by bbuttry »

EXTERNAL TEXT FILE:
[copy1]blah, blah, blah, blah, blah.[ENDCOPY]

[copy2]blah2, blah2, blah2, blah2, blah2.[ENDCOPY2]

[copy3]blah3, blah3, blah3, blah3, blah3.[ENDCOPY3]


REGEX:

Code: Select all

$textfile= "info.txt";
$handle = fopen($textfile, "r");
$contents = fread($handle, filesize($textfile));
fclose($handle);

$output = preg_match('/\[copy2\]([^\]]+)\[/', $contents, $matches); 
print  $matches[1]
OUTPUTS:
blah2, blah2, blah2, blah2, blah2.
vixtran
Forum Newbie
Posts: 5
Joined: Thu May 04, 2006 7:53 am

[SOLVED]

Post by vixtran »

thanks bbuttry.. for the help.. I have read and read and reading.. learned a lot works great!!
Post Reply