Staredit Network

Staredit Network -> Computers and Technical -> Website assistance
Report, edit, etc...Posted by Wilhelm on 2006-04-28 at 21:11:40
Well, seeing as my old topic is essentially dead, and my problem has changed, I'm gonna make a new topic here. Before I post about my PHP woes, I'd like to know if there a way to recall text from a .txt file then modify it with HTML tags. It'd make what I'm doing tons easier.
Report, edit, etc...Posted by BeeR_KeG on 2006-04-28 at 22:08:06
You could use the include("file.extension"); and then place the HTML before and after the text, by using an echo statement.
Report, edit, etc...Posted by Shmeeps on 2006-04-28 at 22:33:26
Yes, pretty simple:

CODE


$filename = "{FILENAME}";

$file = fopen($filename, "r");

$filesize = filesize($filename);

$text = fread($file, $filesize);

fclose($file);

//Do this as many times as nessecary:
$text = str_replace("{INPUT}", "{OUTPUT}", $text);

echo($text);


This will open the file declared as the variable $filename. It reads the whole thing and saves it as variable text. Then, for each HTML tag you need to replace, copy the str_replace function. INPUT is what the function looks for, and it replace that with OUTPUT. Then echo the variable $text.

If you need anymore help, just ask.
Report, edit, etc...Posted by O)FaRTy1billion on 2006-04-29 at 01:56:10
Instead of doing $text = str_replace("{INPUT}", "{OUTPUT}", $text); 5 million billion times, why not do this?
CODE
$whatever_input = array("input", "input", …, "input");
$whatever_output = array("output", "output", …, "output");
$text = str_replace($whatever_input, $whatever_output, $text);

5 million billion array entries instead of 5 million billion lines. tongue.gif

hopefully I didn't massacre that >< I am still newb at PHP. But I have used str_replace with arrays before, and php.net has an example with them.
Report, edit, etc...Posted by Centreri on 2006-04-29 at 10:03:56
They about listed it, but why use a text file? Why not a pre-tagged .html file, and simply include() or require() it?
Report, edit, etc...Posted by Shmeeps on 2006-04-29 at 16:06:17
QUOTE(Centreri @ Apr 29 2006, 09:03 AM)
They about listed it, but why use a text file? Why not a pre-tagged .html file, and simply include() or require() it?
[right][snapback]475334[/snapback][/right]

He may have something like a forum that saves plain text to a file with something like BBCODES, and has to change them on the fly.

QUOTE(O)FaRTy1billion @ Apr 29 2006, 12:55 AM)
Instead of doing $text = str_replace("{INPUT}", "{OUTPUT}", $text); 5 million billion times, why not do this?
CODE
$whatever_input = array("input", "input", …, "input");
$whatever_output = array("output", "output", …, "output");
$text = str_replace($whatever_input, $whatever_output, $text);

5 million billion array entries instead of 5 million billion lines. tongue.gif

hopefully I didn't massacre that >< I am still newb at PHP. But I have used str_replace with arrays before, and php.net has an example with them.
[right][snapback]475175[/snapback][/right]

As for this, it should work, but personally, I'd do it different then both of these. I was just saying that if he only needed a few changed he could do that.

For me, I'd store all the changes that take place in a MySQL database, then grab them all and cycle through them, changing them in a loop.

All of these ways should work, it's up to you to decide which on to use though.
Report, edit, etc...Posted by Wilhelm on 2006-04-29 at 16:15:01
It's a PHP posting system, whenever I try to make it output an HTML file it really screws up. I'm not going to bother with changing it to outputting an HTML file, this is alot easier. I'm kinda confused as to what things I should replace with what and were I should put this code. I'm using Rexy's posting system that she posted a link to in the old thread... urgh.
[attachmentid=18553]
Anyone mind doing this bit for me?
Report, edit, etc...Posted by RexyRex on 2006-04-29 at 19:50:15
That script was dedicated for someone who needed something like that, it wasn't exactly meant to be modified therefore the coding is sloppy. smile.gif
Report, edit, etc...Posted by Mr_Mooo_Cow(U) on 2006-05-01 at 07:39:56
why not save to a database rather than a file?
Report, edit, etc...Posted by Doodle77(MM) on 2006-05-01 at 15:59:33
Because many people have no idea how the f to get mysql working. Like me.
Serialized arrays > MySQL when it comes to ease of use.
Report, edit, etc...Posted by Mr_Mooo_Cow(U) on 2006-05-01 at 21:53:24
thats why I made a ghettofied PHP class file to simplify the MySQL query functions into something I can use off memory.
Report, edit, etc...Posted by Centreri on 2006-05-02 at 14:44:19
I just hate the regular MySQL format. It's so far away from standard programming rules and closer to the english language, it hurts.
Report, edit, etc...Posted by Wilhelm on 2006-05-03 at 17:41:19
I barely get PHP, don't shove another programming language down my throat.
Report, edit, etc...Posted by Shmeeps on 2006-05-03 at 17:55:33
MySQL is more of an extension of PHP. Although it can be used by itself, it's more commonly used by PHP or Python.
Next Page (1)