Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. I dunno any function that takes an array to file output (the inverse of file). u can do it line by line or implode the array, and use file_put_contents.
  2. That depends on the size of the file yer trying to read the code posted just shows different ways of parsing the lines if its small, able to fit in memory u can use many of the code excerpts, and replace the array with $fields=file('filename.txt'); however if the file is larger, u will need to parse it line by line as well as outputting it. with fopen, fgets, fputs and fclose
  3. npp is good, but its not meant for php debugging. Its good for writing code in general, but is not specific to any one language or for programming.
  4. As I stated above, I noticed that the delimeter was double spaces. u can do it with str_replace instead of using all those preg_replace statements <?php $fields[]=' 2981 Rxxxe, Vixxxnt 1 Flixxxxs Clxxxe Axxxy Co.Kildare'; $fields[]=' 2982 Bxxxxe, Anxxxxe 2 Flxxxrs Cxxxxe Axxxy Co.Kildare'; $fields[]='L 2983 Vxxxie, Alxxxxra 4 Flixxxxs Cxxxxe Axxxxy Co.Kildare'; foreach($fields as $i=>$field) { $field=str_replace(' ',',',$field); $field=str_replace(', ',',',$field); $fields[$i]=$field; } print_r($fields); ?> which generates: Note that we compress the comma space sequence for first and last name
  5. Zend Is Great Nusphere PHPEd is pretty good as well lots of tools for debugging as well as code writing (tool tips when ya enter functions, code completion) but if ya dun need all the snazzy stuff, there is DevPHP (OpenSource) which works with xdebug (OpenSource). and is quite small.
  6. Looking at it I do see the delimeter, double spaces problem will be the comma between first & last name, this means ya will have to replace the comma with something else or in yer csv document make room for both first & last name u can use implode,explode or str_replace for the double spaces good luck
  7. $letter=ord('F'); // Get character value of Letter for($i=0;$i<10;$i++,$letter++) echo chr($letter).' '; Simplest way I can think of
  8. thats because xitami isnt set up to run php. most web servers arent out of the box. google 'xitami php setup' there are a number of guides out there to help u with it
  9. First before u begin a timing script. Remember php runs on the server. So yer options for updating the time is by refresh or by loading the screen. if u need an actual count down/up timer u will have to go and use javascript/flash orsimilar which runs in the browser. If refreshing the page, u will also have to consider that this may disrupt the input of text boxes, Search boxes, etc. if thats ok, than yes it can be done in php
  10. Them cheap hosts will give u unlimited bandwidth. As Much info ya can shove thru a straw tho. They are wut ya pay for. They are good only for developing a site (pure html, as your site will be sharing the server with 100's of others) so scripts will lag a lot. So if ya dun mind the slow load times or the slow processing time of scripts. Than shure ya cant beat them cheap hosts.
  11. Use a loop and store the data wut good does it do u if u dont store the pages, if yer trying to minimize the amount of retrievals. $sites=array('http://www.site.com/','http://www.site.com/2','http://www.site.com/3','http://www.site.com/4'); foreach($sites as $idx=>$site) { $filename="test{$idx}.html"; $contents=''; if(file_exists($filename) && ((filemtime($filename) + (4 *3600)) < time()) $contents=file_get_contents($filename); else { $contents=file_get_html($site); file_put_contents($filename,$contents); } } This shud work note the 4*3600, this is amount of time (4 hrs) to use our cached files
  12. Yes, but it fails the condition of capturing the path only. so even tho salkin's method is a bit longer it does wut was requested. but ya may want to look at parse_url function instead and play with that instead of using regex
  13. I used something similar (w/o counting), to provide subcategories of unlimited depth to a download area. This way things could be very organized and looking them up would be simpler. I used Thr Tree Based structure which u have. than i built a cached index, so i wudnt have to keep rebuilding the tree. since the counting is very important, ya may consider keeping a counter updated so ya dun have to build the tree in order to get a count as this will take the most amount of time. Trees and Recursion, its a lot to take in, and at times may cause headaches, but it can be done.
  14. I myself prefer using the sqlite session handler as with mysql sessions, ya will have to look it up to enable it with php.ini. but if offers best of both worlds, its fast & small
  15. u can use the gdimage that comes with php, but its not a shure fire way to prevent scripts. so maybe just a header check, and a filename check will suffice $it = @exif_imagetype($file["tmp_name"]); if (!($it == IMAGETYPE_GIF || $it == IMAGETYPE_JPEG || $it == IMAGETYPE_PNG))) die("Upload failed. Sorry, the file you uploaded was not recognized as a valid image file."); should do well for image checks, but as stated its not full proof. but makes it quite a bit harder. the next step, is not to save it as a usernamed filr, either rename it or store the original filename in the db. prolly renaming it is simplest way, giving it some arbitary number (or just use md5 to generate the name). Renaming it yerself also prevents users from overwriting other ppls uploads as well... good luck
  16. Yer quite welcome, nice thing about using xor, is that u can use it in different languages. since most have this bit operator, so no extra libs required, but again its very simple technique. so isnt as hard to break as other techniques
  17. Thanks, yeah, different languages have different function names
  18. This is really basic, U should look at pagination which is the same process, or alternating color sequences. How to slice up 500+ messages to 25 per page. The whole thing is about keeping a counter. <?php $text="A65A65cB5A65" $key="1234" $max=3; // Three Character max per key $klen = len($key); $ctr=0; // Yes our counter; $kpos=0; // Key Position $et = ''; // Encryted Text for($i=0;$i<len($text);$i++) { $tc = substr($text,$i,1); // Grab 1 char from text $kc = substr($key,$kpos,1); // Grab 1 char from key $nc = ord($tc) ^ ord($kc); // Simple encryption logic, get ascii values and xor them $et .= $nc ; // Add it to our encrypted string $ctr++; if($ctr==$max) { have we reached our max limit $ctr=0; //reset our counter; $kpos++; // increment our key position if($kpo>=$klen)) $kpos=0; // if we are over our key, reset to beginning } } I think that shud work as is, but this is not tested. using a xor to encrypt is very simple method indeed, but it works, and ya can use the same method to decrypt the encrypted text with the same key. Good Luck
  19. Use a database and a cache The database will house yer strings. while the cache, houses the preprocessed pages (lowering the load time for the pages) the db for the strings can be simple. One table for the language names and one for the strings themselves create table languages ( id INTEGER PRIMARY KEY, language VARCHAR(32) ); create table strings ( id INTEGER PRIMARY KEY, lid INTEGER, sid INTEGER, string VARCHAR(255) ); The languages table is optional, but it is nice to have to add/remove languages and provide a drop down box for the strings, u will use lid = language id and sid = string id now ya can build a string editor, In a few sites, I always used english as 1, this way when I built the editor. I can use the english strings as the default for the editor.
  20. yes, but for some reason it's not letting u access the file. not shure where to go from this point
  21. looks like a missed an end paren if(!($ctr=file_get_contents('hit_counter.txt'))) { parens are good for seprating blocks, but they can get confusing when ya looking at how many levels they are
  22. U can replace this section $filename = "hit_counter.txt"; @$fptr = fopen($filename, "r+"); if ($fptr == NULL) { @$fptr = fopen($filename, "w+"); fwrite($fptr, "1"); fclose($fptr); echo "1"; } else { $data = fread($fptr, filesize($filename)); $dataInt = (int) $data; $dataInt++; rewind($fptr); fwrite($fptr, $dataInt); fclose($fptr); echo $dataInt; } as both are doing the same thing check if file counter exists if it doesnt exists, start with 1 if it does exists, increment counter save new counter echo counter. For not being good with php, you are doing fine But as programmer's know, there is more than one way to skin a cat. Good Luck agian
  23. follow the logic of yer code $filename = "hit_counter.txt"; @$fptr = fopen($filename, "r+"); if ($fptr == NULL) { @$fptr = fopen($filename, "w+"); fwrite($fptr, "1"); fclose($fptr); why wud u close the file, when a little later u write to it. there are simpler ways of doing all that code in simpler solution if(!($ctr=file_get_contents('counter.txt')) { $ctr=1; } else { $ctr++; } file_put_contents('counter.txt',$ctr); echo $ctr; Anyways good luck
  24. U may want to look at hjsplit. It may add some inconvencience to the user on his end. as they have to split the file on their end first, upload the individual parts. but if has a number of flavors, including one for php (so u can look at and create a script to rejoin the split parts). Including a java version (so they dun need to install anything on their pc, just run the java version from yer site, split the file on their pc, and upload the pieces). Anyways good luck
  25. Yes, thats the system Im used to as well KingPhillip. But I over the years, i got tired of the hierachy system. And now a days I use a flag system instead. Which seems to work out better for me, since I want a flexible and be able to serve groups within the community as well. With the hierarchy system, if create 3 groups (groupA, groupB, groupC). u will end up adding code for each group to test for the group affiliation. than it just gets complicated if u add a moderator to that group. as now u have to create yet another user type. so now a days i prefer the flag system. Where I can define different areas of the system, and give access according to wut I want. I believe best way to see the flag system, is by looking at several apps that have it in place. such as TikiWiki. Where U can define a default set of flags for different user groups, but still allows u to assign an individual overriding flags. Anyways good luck
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.