Page 1 of 1

load info from text doc

Posted: Thu May 04, 2006 8:04 am
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!

Posted: Thu May 04, 2006 9:28 am
by feyd
code? example data? example output?

Posted: Thu May 04, 2006 9:47 am
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]

Posted: Thu May 04, 2006 9:55 am
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.

Posted: Thu May 04, 2006 10:47 am
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?

Posted: Fri May 05, 2006 9:28 am
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

Posted: Fri May 05, 2006 11:01 am
by feyd
Read our regex tutorials and the links I provide about regex in Useful Posts.

Solution

Posted: Fri May 05, 2006 2:21 pm
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.

[SOLVED]

Posted: Fri May 05, 2006 4:01 pm
by vixtran
thanks bbuttry.. for the help.. I have read and read and reading.. learned a lot works great!!