|
dee
|
 |
« on: July 20, 2008, 02:46:50 PM » |
|
evenin..
ok. So im sloooowly teaching myself php and lovin it ( no flaming for language choice please ! that would assume i know the differences......) Anyway. So i am know the proud owner of my first auto site ! woo hoo ! after many hours of hair pulling i have a site that will look at a config file, read a keyword or two and go get pictures and some rss stuff and display it in a very ugly fashion. I know this is very basic in terms of what you guys are doing but am proud as fish of it !!!
Would anyone be so kind as to point me in the direction of my next problem. Automating it ! Say for example i had 1000 keywords in a txt file all on a seperate line. How could i write a 1000 folders with each keyword name containing a config file with the variable $keyword= "same as folder name"
does that make sense? Whats the best path to pursue?
cheers!
|
|
|
|
|
Logged
|
|
|
|
|
dee
|
 |
« Reply #1 on: July 20, 2008, 02:50:03 PM » |
|
Can i just also say...i only got to this stage with the help of people on this forum and the one i was invited from. Not meaning to blow smoke up peoples asses....but cheers to those that had the patience. Nice.... 
|
|
|
|
|
Logged
|
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #2 on: July 20, 2008, 04:37:33 PM » |
|
First off, congrats Dee on your first dynamic site and it sounds like you are making steady progress. PHP is a fine language, you'll not get any flame here for using it. Except from NOP, of course, but you'll just have to get used to that  @ 1000 KWs and 1000 configs and and... sounds like you're moving quickly towards a database requirement. Do you know anything about SQL, MySQL or using databases? Your host will probably provide you with one, and then you'll use the mysql_ functions in PHP to talk to it. There are an awful lot of us with a tremendous amount of experience in that realm and I strongly recommend that you take the time to invest in learning that right now, rather than trying to gut this out with Ks of text files, which is just a really bad plan. Additionally, if you can get an instance of phpMyAdmin working against your database, you'll find that it is pretty easy to administer, quick to edit/update and pretty damn fast for web requests (provided you've got things lined up OK). And thanks BTW for the smoke up the ass... always appreciated 
|
|
|
|
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
|
nutballs
|
 |
« Reply #3 on: July 20, 2008, 05:24:12 PM » |
|
i may be basic dee, but its the whole point. everything else is just bells and whistles. So if you got this far, the next steps are just building blocks on the foundation you just built. until of course you realize your foundation is shit and then start over... but thats a bit down the road. for now, great and grats. for keywords. perk is right that DB is the way to go, however, lets ignore perk for a minute. You can do this very easily. I am not going to spell it out of course, that wont help you learn. read these pages: http://us.php.net/manual/en/function.fopen.phphttp://us.php.net/manual/en/function.fread.phphttp://us.php.net/manual/en/function.fwrite.phphttp://us.php.net/manual/en/function.mkdir.phphttp://us.php.net/manual/en/function.is-dir.phphttp://us.php.net/manual/en/function.is-file.phpbasically, open then read, then loop through lines writing each to a dir and files. short and sweet. those are the functions you will need. to piece them together is up to you. post with questions of course  But again, I would agree that mysql is the right way to go overall if you have it available. I fully understand though, the potential environments this type of system will be deployed to, might not provide all the best features, or even any features at all... so then the text file method is good.
|
|
|
|
|
Logged
|
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #4 on: July 20, 2008, 05:28:30 PM » |
|
what fuck? sound like nuts login with nop password. fuking weird. perhaps it's microbrew time at the NBs residence. cheers. Oh, forget php and code it all in LISP. only way to go.  (sorry for the fun @ your expense nop) Nice post NBs
|
|
|
|
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
|
nutballs
|
 |
« Reply #5 on: July 20, 2008, 06:06:02 PM » |
|
nah my post didnt have enough crazy ass ((()))()()()())))()((())(()()) to be nop. 
|
|
|
|
|
Logged
|
|
|
|
|
dee
|
 |
« Reply #6 on: July 21, 2008, 02:32:40 AM » |
|
thanks for the replies ! all good input. I guess until i get a bit further down the road and understand a bit more i might stick with NB's solution. As it happens, part of what ive done so far involves reading a bit of random text from a text file using fopen and read so i get the basics of how it works. The down side of that is that the txt files involved see quite large when your dealing with picking a random sentance from a 30000 choices ! And do that with 50 different sentances and it adds up pretty quickly....I guess whether sql or txt the file sizes are going to be large so not much difference I guess thats another question i could ask you guys. Does that seem like a good way to go about the content generation? From what ive read so far here and on syndk8, half the battle seems to be content. The other half is getting it passable to bots and even possibly human eye?? I like the idea of not having to worry about getting zapped because content is just bollox with keywords thrown in. It seems this way i can make it readable....although i know a lot of work is involved in setting this up so every sentance will track into next etc etc...what you think? either way i guess id better get my reading hat out !  cheers all
|
|
|
|
|
Logged
|
|
|
|
|
nutballs
|
 |
« Reply #7 on: July 21, 2008, 07:28:55 AM » |
|
there are two approaches. Good and Good Enough. I go with Good Enough. Which for me is, no misdirection (send them to something that is actually related to what they were looking for) and content that is human readable (mostly) at the sentence level, retarded monkey typewriter sounding at the paragraph level. I also don't let them see the content if I dont have to, but I dont stress about it, so I use a JS redirector, a little more advanced than some of the other fodder you might see out there. Not as strong as something perk might use, but then again, he has to stress about it because of this clients.
|
|
|
|
|
Logged
|
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #8 on: July 21, 2008, 09:05:44 AM » |
|
If you are looking at 30K choices and picking a random sentence from that lot with either a text file or SQL there will be no comparison between the two: the textfile will lose big to SQL (again, provided you do it reasonably well) and here's why: if you load a 30K sentence file every time in front of a page load and then select 5 random sentences you really only have two options: load the whole ball of wax into a string, explode it into an array and then pick 5 OR create a fixed-length file and do 5 fseeks to random positions and pick up your sentences (in which case you've just reinvented the database) - in either case, the load on the page will be pretty damn big. On the other hand, if your 30K strings are in a DB, you'd put an autoincrementing integer as the ID on the first column and your string on the second. Then you could do 5 SQL selects and you're in and out in the wink of an eye. For this example I'm going to use the dbConnection class, available here in the repository, because it reads nicely: <?php
require "/www/lib/class.dbconnection.php";
$db = new dbConnection('127.0.0.1', 'username', 'password', 'mydb');
$max = $db->singleAnswer("select max('id') from sentencetable");
for ($i=0; $i<5; $i++) $pos[$i] = rand(1, $max);
$sql = <<<SQL select sentence from sentencetable where id={$pos[0]} or id={$pos[1]} or id={$pos[2]} or id={$pos[3]} or id={$pos[4]} SQL;
$db->query($sql); while ($db->fetchRow()) echo $db->row[0];
?>
... I wrote this in the way that I did specifically to spin your gears a bit. There are several interesting tidbits of ways to code PHP as well as working with a database in there.
|
|
|
|
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
|
dee
|
 |
« Reply #9 on: July 21, 2008, 10:08:45 AM » |
|
thanks for the explanation guys. The difference makes sense now. Although...originally my plan is to then write each page as its own keyword based html page, so any generation is done offline on the server...therefore the reader is loading a static html page. I was planning to input a list of keywords and have it looped through, with each keyword being injected into template with random text and then the whole page written as static html. Im sure im probably reinventing the wheel here...but hey... im trying to do it so i learn from first principles. Speaking of which.. quick question again ! Ive just cobbled together a loop to read a text file (using suggested reading material  . and then make a folder named for each line. I kinda got it working. I have a txt file with the number 1,2,3,4 in there on seperate lines.... and the echo statement works fine(just in there to test loop) however it only writes one folder (number 4 ) Any clues please? Heres the code.. <?php $text = file('folders.txt'); // loop through array and output contents foreach($text as $line) { if(!is_dir("$line")){ mkdir("$line"); } echo $line ; } ?> Thanks !
|
|
|
|
« Last Edit: July 21, 2008, 10:10:59 AM by dee »
|
Logged
|
|
|
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #11 on: July 21, 2008, 11:09:17 AM » |
|
side question... if you are running this script via a call through Apache, does that daemon have write rights to that directory? That's an important thing to consider in your future deployments. You'll probably need to make the root directory 777 so that anyone (ie., the Apache daemon) can write to it.
file_get_contents will be plenty fast enough for this purpose (it's pretty damn fast in any case).
$buff = str_replace(chr(13), '', file_get_contents('./thefile.txt')); $lines = explode(chr(10), $buff);
In this example, we remove any chr(13)s that might be in the file, using chr(10) as the line-delimiter. Then explode on that. These two lines are pretty standard for this sort of thing, because you never know of a file was delimited as chr(10) + chr(13) or just chr(10) or, in the worst extreme, old Mac format (<2000) chr(10) + chr(13) (WTF were they thinking?)
Give that a shot.
|
|
|
|
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
|
dee
|
 |
« Reply #12 on: July 21, 2008, 03:24:13 PM » |
|
THANK YOU THANK YOU !!
WOO HOO...have had my first proper lightbulb moment ! it fishin works ! thanks to you both...went and read about file_get_contents and then str_replace and it made sense !!! SO here is my first proper self written code project.It takes a line seperated txt file, checks the contents and either makes a folder or if it already exists skips it :
<?php //use str_replace to replace carriage return with ' ' in txt file.Eliminates delimiter problem(cheersPerkiset) $buffered_file = str_replace(chr(13), '', file_get_contents('folders.txt'));
//take buffered file and split using chr(10) as delimiter $array = explode(chr(10), $buffered_file);
//for array..loop through each one and call $data foreach($array as $data) {
//if folder exists say so if (file_exists($data)) { echo "The folder \"$data\" exists! " ;
//if folder doesnt exist then make one... } else { mkdir("$data"); echo "The folder \"$data\" has been created! " ; } } ?>
Still not sure i understand the difference between chr(13) and chr(10)...but hey... its workin.
Thanks again guys.I actually learned some shit.
|
|
|
|
|
Logged
|
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #13 on: July 21, 2008, 03:56:44 PM » |
|
chr(13) and chr(10), also know as hex 0x0d and 0x0a are two characters used to define a line break. Technically, chr(13) was a "carriage return" which is old-fashioned speak for when a typewriter's carriage was moved back to the far left (well, the carriage went far right, but the type-impacter was now at the far left of the page) and line feed ( chr(10) ) was for when you hit the big arm on the right side and the roller moved the page up. Ergo, a CRLF moved the caret to the far left on the page and down a line. These two character were used for the longest time on BBS systems, teletypes and dumb terminals for character positioning. This was modified many many years ago when Linux simply used chr(10) to define a new line... thus, it was named a newline character and the PHP equivalent is "\n" . Carriage return is still defined in php as "\r" . Several systems persisted in using the entire line structure most notably Windows, which uses CRLF to this day. For many years, and for no divineable reason except unto God himself, the apple team chose to define a newline as chr(10) + chr(13) which caused huge compatibility problems between the Mac format and Windows. IMO, this single little decision may well be responsible for the YEARS that Mac spent languishing as a proprietary system. Whoever thought that neat trick up is one smart mofo. 
|
|
|
|
« Last Edit: July 21, 2008, 03:59:59 PM by perkiset »
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
perkiset
Olde World Hacker
Administrator
Lifer
   
Online
Posts: 5230
:sniffle: Humor was so much easier before.
|
 |
« Reply #14 on: July 21, 2008, 04:01:06 PM » |
|
In case you're still not getting it 100%, a chr(65) is a capital A ... so if you were to echo out chrs 65..90 you'd get the capital letters of the alphabet. Chr(32) is a space etc etc. Look up ASCII table in Google and you'll see what I mean.
|
|
|
|
|
Logged
|
If I can't be Mr. Root then I don't want to play.
|
|
|
|