load info from text doc
Moderator: General Moderators
load info from text doc
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!
thanks in advance!
feyd | Please use
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]
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]);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]- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Play with the results from the followingThat should replace your explode() call. You will need to adjust the print() call too.
Code: Select all
$output = preg_split('#\s*&([^=]+)=\s*#s', $contents, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);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
thanks all
Solution
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:
OUTPUTS:
blah2, blah2, blah2, blah2, blah2.
[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]blah2, blah2, blah2, blah2, blah2.