Jump to content

laffin

Members
  • Posts

    1,200
  • Joined

  • Last visited

Everything posted by laffin

  1. laffin

    nl2br

    <br /> is xhtml compliant <br> isnt they produce the same results tho
  2. Yes, all pass.php global variables and functions will be accessible from cell.php
  3. 1) I would use bit flags instead of tinyint/bools I posted not to long ago, a set of functions to use bitflags... all the knowledge you need is that integer fields are 32 bits, so you can have a total of 32 flags, a tiny int is 8 bits, so you can use a tinyint in your db, but you would have to assign it as unsigned tinyint, as mysql would consider a tinyint int the rage of -127 to 128, and php only works with full ints. BitFlags Quick Start
  4. this should work as a pattern string
  5. could also be that mkdir doesnt handle subdir creation. in other words, it cant make a dir if the parent doesnt exixst. but it could be a lot of things. as Gizmola said, have to trace down the problem. than come up with a solution.
  6. I think your close Gizmola, but there is a serious flaw in the code. It only supports one ad, 'viewcount'. But it does seem to be on track. You will probably add some fields to the db, to have these conditions in place. and use most of what Gizmola has said/coded as a guide. and depending on the amount of ads, you may want to avoid a cookie altogether. if its low amount of ads, than it will work fantastic. but if u have a large number of ads, storing this amount of info in a cookie could exceed limits of the max size cookie (4kb/4096 bytes); The hard part is going to be, ad selection, as Gizmola said, in order to set a cookie, nothing should be sent for display. so the ad selection, should be above your display section, in order to set/adjust a cookie
  7. well there can be one other tweak ya can do, since there are no ' or \ in your regex captures replace ([a-zA-Z-0-9\_\-]+)'s .* with ([a-zA-Z-0-9\_\-]+).*
  8. Just a matter of array lookups using your array structure, in order to find the 'Lamp', you would have to iterate thru each item in your array, until you find the item. the second is a bit more convienent, when doing lookups for the item but when dealing with databases, its faster to use INTEGERS as primary keys, and integers are more easily validated/processed in web apps. so it really depends on the usage of your array, if you want to use a named index key system or an integer index key system. The named index key system also helps when debugging code as well as others to read your code without a lot of stuggle I use both systems depending on their usage in my apps, So I think, she means by readabilty. its easier to understand this in your app $price = $item['lamp']['price] + ($item['lamp']['price']*$tax) + $item['lamp']['shipping'] than it is this $price = $item[2][1] + ($item[2][1]*$tax) + $item[2][2];
  9. I still don't see the problem, all values are returned by their ascii sorting order, Upcase first, lcase second
  10. here is the sample code, I came up with <?php function build_dir($cdir='./') { $dh=opendir($cdir); $dir=array(); while($file=readdir($dh)) { if(substr($file,0,1)=='.') continue; // if directory/file is . (self), .. (parent) .Filename (hidden). Ignore and continue if(is_dir($cdir.$file)) $dir[]=array($file,build_dir($cdir.$file)); else $dir[]=$file; } return $dir; } function sort_dir(&$dir) { $subfolder=array(); foreach($dir as $key=>$file) { if(is_array($file)) { $subfolder[]=$file[0]; $subcontents[$file[0]]=$file[1]; unset($dir[$key]); } } sort($dir); rsort($subfolder); foreach($subfolder as $folder) { sort_dir($subcontents[$folder]); array_unshift($dir,array($folder,$subcontents[$folder])); } return $dir; } function show_dir($dir,$level=0) { $indent=str_repeat(' ',$level*2); foreach($dir as $file) { if(is_array($file)) { echo "{$indent}[{$file[0]}]\n"; show_dir($file[1],$level+1); } else echo "{$indent}{$file}\n"; } } header('Content-Type: text/plain'); $dir=build_dir(); show_dir($dir); echo "\n"; sort_dir($dir); show_dir($dir); This was my first thoughts on going about it, so I know a lot of optimization could be done. But it works
  11. for that u need to install PECL extensions, which requires PEAR
  12. look into pathinfo() and parseurl() functions
  13. U do know that uppercase characters proceed lowercase characters? I think a sample of the sort of what you are seeing and what you expected should be included
  14. The sort routine was pretty similar, it required recursion, the first task was to seperate the $foldername from the $contents ($contents being an array of more folder contents) the foldernames were just a simple array, the contents used the foldername as the index (key). Sort the foldernames, than go thru them sorting the contents with a recursive call. recombing them according to the sorted foldernames there might be an easier way, but this was my first thoughts on accomplishing such a task
  15. CREATE TABLE accts ( acct INTEGER NOT NULL PRIMARY KEY UNIQUE, name VARCHAR(45) NOT NULL DEFAULT '' ); since accts will be unique, you dont need an autoincrementing id. just use the account number, when inserting accts to the db, any duplicate will fail the UNIQUE contraint, so wont get inserted, and returns an error code.
  16. it was a pretty interesting task. done some sample code and it worked out very well. But I used a file/dir hierechy system. but if your just dealing with folders, than use recursion routines i wrote up, have an array system of $folder[] = array($foldername,$contents); where $folder is the foldername, and $contents is a recursive call of the function returning an array.
  17. are account numbers unique? if so use the first as a primary key field non null unique field. you dont need to recreate the db, if new accts are added, but if removed, you will (or u will be building a system with lots of extra code checking db against txt) when u insert items into the db, since the acct number is set as a unique field, it will fail to insert those duplicate accts. u can verify with the sql_error code.
  18. before the preg do something like: $sabData=stripslashes($sabData); it sounds like your php configuration has magic_quotes enabled, so it adds extra stuff on php.net, someone posted a portable solution which u would add/include to the top of your scripts.
  19. I still get outputted with using only var_dump $intel containing a total of 8 array elements. with element 0 being the entire string. But if your original string has a \ in front of the ', than thats what is causing the failure, usually \' are added when you insert string items into your db, u can fix that by either using string_replace, or modifying the preg patthern to include the \'. which would look like: \\\' instead of \', the backslash in preg means its a direct character not to be confused with its metacharacters.
  20. Problem is you only get a string of the first result from sql. You should start with a empty string, append results, and than return the string function getCC() { require('db.php'); $selects=null; $query = mysqli_query($conn, "SELECT complaint FROM complaints"); while($row = mysqli_fetch_array($query)) { $selects .= "<option value=\"" . $row['complaint'] . "\">".$row['complaint']."</option>"; } return $selects; }
  21. if your uploading via ftp, be shure its in binary upload format, and not text format.
  22. go one step further oni-kun lang.en.php $langstrings =array( 'hello'='>'Hello', 'bye'=>'Good Bye', ); lang.sp.php $langstrings = array( 'hello'=>'Hola', 'bye'=>'Adios' ); lang.fr.php $langstrings = array( 'hello'=>'bonjour', 'bye'=>'au revoir' ); so main code can go something like this $lang='xx'; // give some goofy language $lang = file_exists("lang.{$lang}.php"?"lang.{$lang}.php":"lang.en.php"; // select out language file, if not exist use default en. include($lang); // load our language file echo "{$langstring['hello']}"; a simple method, with an intermediate level of maintainance.
  23. $intel is an array. just depends how many groups you have. they are numbered from 0 to X (x is amount of groups in the pattern) for the example here it would return an array like: This is reason I used var_dump (print_r would have worked as well)
  24. Your pattern match is ok, but your replacement is foul. I think you should use preg_match instead, to pull in the variables. $data = "/.*? dispatches ([0-9]+) .*? sabotage ([0-9]+) of ([a-zA-Z-0-9\_\-]+)\'s .*" ; $data .="type ([A-Z]{1}[a-zA-Z0-9]+)\."; $data .= ".* enter ([a-zA-Z-0-9\_\-]+)\'s .*"; $data .= "destroy ([0-9]+) of the enemy\'s ([A-Z]{1}[a-zA-Z0-9]+)/"; $str=" Your Chief of Intelligence dispatches 1 spies to attempt to sabotage 3 of cain536's weapons of type Shield. Your spies successfully enter cain536's armory undetected, and destroy 3 of the enemy's Shield stockpile. Your spies all return safely to your camp."; preg_match($data,$str,$intel); var_dump($intel); which should return an array of the items ya want extracted (element 0 of the array is your string, so that can be discarded)
  25. use sessions. this way, no matter which page they goto, u will have which language. I've seen a number of ways of doing this. 1) create a subdirectories for each language - prolly the easiest, but also means a lot of maintainance. 2) create a lang folder / with lang php files - intermediate, but maintainance is a lot easier, as you just need to edit the language files. there are other ways. but those are the most common.
×
×
  • 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.