Closed Thread Icon

Topic awaiting preservation: A Little Lost... (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12671" title="Pages that link to Topic awaiting preservation: A Little Lost... (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: A Little Lost... <span class="small">(Page 1 of 1)</span>\

 
quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 03-29-2003 14:43

Ok, I've taken on a project that I can see myself getting a little drowned under, and would quite like some help in what direction I should be moving in. It's basically going to be a small site for students at my school, where a few of the interested ones can post articles on various topics. These people will obviously not have knowledge of HTML or the mechanics of the web, I don't expect, so therefore I'm going to need some server side stuff to take care of things. The only language (server-side) that I know is PHP, so I'm pretty limited there. What I want is a page where a user can enter a password, upload a plain text file of the article, fill in a few text fields (name, title of article, etc.). Then what the script needs to do is somehow convert the text file into maybe an XML file, with tags enclosing the name, title, content etc. (however I have no real experience with XML. Finally index and display pages for the articles will have to be made by parsing the files and extracting the relevant content. That's an awful lot, I know, especially since I want to avoid a database, but I'd just like a few pointers/suggestions, and whether this is the right direction, and whether this can be done with PHP. Thank you very much in advance.



[This message has been edited by quisja (edited 03-29-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-29-2003 16:34

certainly can be done with php!

But junk the xml idea, though it is a nice data exchange format, it is not something you'd want to store your data in...

I'd propose a YAML like file format, ie. you'd have something like

Title: My title
Author: Someone
Text: Blablabl <br>shcarouhsrocehu<br>

Converting the text for this file could be as simple as calling nl2br() on the string (which incedentially will allow you to preserver your precious new file format, without having to worry about " and < and ' and >...)

Outputing would be not much different. read it in, explode it on "\n", seperate it on the first :, first part is what it is, second part is your data. Print in a nice way.

holler if you need more help,

Tyberius Prime

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 03-29-2003 19:14

OK, I've thought about this some more, and set up a page which will create a file from an input, list all the files created, and print a specified file. The only thing to do now (other than prettyfying it) is to be able to parse the files and extract the title and name info from them. Currently having links to 4727567265.txt aint good. I've Structured the data as follows:
Name: Author McName
Title: Article McTitle
The text of the article goes here unformatted blah blah blah..

And I thought this was going to take ages...

[edit] see/test it here [/edit]



[This message has been edited by quisja (edited 03-29-2003).]

[This message has been edited by quisja (edited 03-29-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 03-29-2003 20:39

looking nice.
Parsing the files should be pretty easy, as long as you remember that none of your data may contain newlines... then it can be as easy as


$lines = explode("\n",$myReadInFile);
foreach ($lines as $aLine)
{
$var = substr($aLine,0,strpos($aLine,':')) //or was it strpos(':',$aLine)? I never can remember
$data = substr($aLine,strpos($aLine,':',),strlen($aLine))
${$var} = $data; //this will yield three variables, $title, $author and $text. Uh, I see you missed the "text:" before your text... be sure to put that in there, makes everything easier.
}

printEverythingNiceAndDandy()

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 03-29-2003 22:33

OK, almost finished on the coding side of this. Only one niggle left, that I can't figure out. If the input in in multiple paragraphs (i.e. there are more newlines than just in the headers) then I only get the first paragraph in $text. How can i fix this?

<?php
//will eventually be a separate function to display available articles
$dh = opendir(dirname(__FILE__) . '/articles/');
while ($filenm = readdir($dh)){
if ($filenm != '.' and $filenm != '..') {
$fh = fopen("articles/$filenm",'rb');
$data = fread($fh,filesize("articles/$filenm"));
$lines = explode("\n",$data);
foreach ($lines as $aLine) {
$var = substr($aLine,0,strpos($aLine,':'));
$data = substr($aLine,strpos($aLine,':'),strlen($aLine));
${$var} = $data;
}
fclose($fh);
//this removes colons that were at the start of each string
$title = substr($title,1,100);
$name = substr($name,1,100);
print("<a href=\"index.php?f=$filenm\"><b>\"$title\" by $name </b><br /></a>");
}
}
closedir($dh);

//will eventually be a separate function to display article
if (isset($f)) {
$fh = fopen("articles/$f",'rb');
$data = fread($fh,filesize("articles/$f"));
$lines = explode("\n",$data);
foreach ($lines as $aLine) {
$var = substr($aLine,0,strpos($aLine,':'));
$data = substr($aLine,strpos($aLine,':'),strlen($aLine));
${$var} = $data;
}
fclose($fh);
//this removes colons that were at the start of each string
$title = substr($title,1,100);
$name = substr($name,1,100);
$text = substr($text,1,1000000000);
print "<h2>\"$title\" by $name </h2>";
print nl2br($text);
}
?>

sorry, this is messy and probably overlong

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 04-01-2003 16:34

Thanks very much for the help, it's all up and running now, and ready for tomorrow's launch... http://members.lycos.co.uk/patespolitics (check out the articles sections for the php). Thanks again, couldn't have done it without you...

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-01-2003 18:48

quisja how did you fix your paragraph issue? because I've been haveing the same one with a script of my own


quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 04-01-2003 19:32

*looks embarrased* um basically I ran each article into one long string of text with no line breaks, apart from in the headers, with <p> tags between the paragraphs. I could imagine having to rewrite the code otherwise, and I didn't feel up to that.

Trigger
Paranoid (IV) Inmate

From:
Insane since: Jun 2002

posted posted 04-01-2003 19:42

LOL, I think im going to have to Resort to search for HEX A0 I think it is :S and replacing it with <P>'s .. wich should be ehum....fun..



« BackwardsOnwards »

Show Forum Drop Down Menu