Jump to content

genericnumber1

Members
  • Posts

    1,858
  • Joined

  • Last visited

    Never

Everything posted by genericnumber1

  1. 1/1970 corresponds to 0 seconds unix time. It's likely that strtotime() is failing and returning false. PHP is then casting the false to an int to make 0. The manual lists "Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC" are the valid time ranges, so your method will not work for dates as early as 1/3/1900. The reasons for this limitation are fairly technical and not really super important to understand unless you're curious, just know that you should use another method if you want to do dates very far in the future or past.
  2. The reason it works is because it saves all of the content you output in a output buffer. ob_start means "save all echos, print_rs, etc in a string (output buffer) instead of outputting it to the browser" and ob_flush or ob_end_flush outputs all of the content in the buffer to the browser. It's not really a FIX to the header() issue, it's more of a hack job, but it works.
  3. Firebug is a browser extension. There is no way of doing this using any legitimate technology.
  4. Extensions are typically programmed in C and compiled into a dll. You can, on the other hand, auto include files in the php.ini, but that's not at all portable and you should avoid doing it.
  5. If all of that is encased in a while loop (you should have included it, btw) then it's because your redefining $img each time it loops, so it only exists after the last iteration of the loop. Move the $img definition outside of the loop and you should be fine. If that's not your problem, could you show us the full code including the loop and definition of these variables you are using? Nevermind, glad you got it working
  6. The simplest way would just be to set it if it's not set... so the loops become <?php foreach($arrArgs as $arrItem) { foreach($arrItem as $k => $v) { if(!isset($return[$k])) { $return[$k] = 0; } $return[$k] += $v; } } ?> Obviously I didn't check your logic since you said your answer was correct.
  7. Long version: Well it depends, are you programming like an object oriented programmer? If so, you should be creating objects and performing actions ON those objects, not just calling methods IN them. At that point it should be clear whether you want to create a new copy of an object or pass the routine an existing one and you probably wouldn't need to be asking us this question. If all you're doing is taking your procedural program and putting it inside of classes, then you're not programming like an object oriented programmer and it would be less confusing to just make the classes/methods static so you don't have to instantiate them to begin with. Once you reach that point, you might just raise the question of "why don't I just program procedurally to begin with?" Short version: If you find yourself creating new classes just to use the methods inside of them and not because you're trying to represent a new "user" or whatever it is your class is supposed to represent, it should probably be a static method. Or, more likely, you're not designing the program in a proper object-oriented manner to begin with.
  8. I much prefer dependency injection to singletons, they're much too global and make unit testing a hassle. Of course singletons are good in some circumstances, but I try to avoid it if possible.
  9. pass it? <?php public function __construct($usersClass) { $this->_users = $usersClass; } ?> I'm not sure I understand your question. Could you elaborate on what you're trying to accomplish?
  10. It had a lot of people posting questions that didn't involve OOP and a lot of OOP questions were put into the normal php forums... I wasn't surprised when it went away.
  11. I know you can blacklist with that, but can you whitelist with those directives like he wants? If so, that's kind of cool, I didn't know that.
  12. str_pad but you don't have to fill it in with spaces to submit it, it's 15 characters max, not 15 character exactly.
  13. There's always a way. Is there a simple way that wouldn't involve countless hours modifying the Php or apache source code? No. Why would you need something like this?
  14. OpenWRT? Are you running this thing on a PDA? Sorry, I have no idea what's causing such an odd issue.
  15. I weep for you when you come back to this code in 6 months. For now though, I guess it's impressive you got it on one line
  16. It's stripslashes, not strip_slashes. And you don't have to copy it to a variable, you can just echo it.
  17. Is there a problem with instantiating a new wowcms object? Did you consider making the method static? Can you pass around the wowcms object between routines? As a last resort, can the wowcms object be a singleton? (I'm not a fan of singletons, but it's still a little better than a global variable) There are plenty of ways to do it other than using global variables
  18. That's incredibly odd... What server are you using?
  19. It's likely magic_quotes_gpc if the ' and " are automatically being escaped when inputted. You can turn that off in the php.ini if you promise to escape all input strings with mysql_real_escape_string before using them in a query!
  20. You can probably nest the ternary operators to get this effect, but unless you're trying to give someone a headache, just use normal if/then/elseif/else statements.
  21. Use aschk's solution only if the file is small enough to all fit in memory at one time. I assumed because he called it a "huge text file" that it couldn't fit in memory at once. Aschk's solution is more simple and faster though if you have the memory to spare.
  22. The safer way which doesn't load the whole file into memory would look something like this... <?php $maxLineLength = 1024; // Longest possible 'word' $oldLineDelimiter = ","; $newLineDelimiter = "\n"; // <br /> if new lines are to be displayed in the browser // Open the file $fileHandle = fopen('/path/to/my/file.txt', 'r'); // Or whatever file name you need if($fileHandle) { // Read each line and output them one-by-one while(!feof($fileHandle)) { $word = stream_get_line($fileHandle, $maxLineLength, $oldLineDelimiter); echo $word . $newLineDelimiter; } // Clean up fclose($fileHandle); } else { echo 'Unable to open file.'; } ?> I didn't test it, so if there's a bug, you'll have to fix it! Don't just copy the code, try to figure out how it works and why I do things the way I do. Feel free to ask any questions, just know I may be asleep by the time you ask them, but I'd be happy to answer them tomorrow.
  23. Are you trying to create a new file with this content or are you just trying to output it?
×
×
  • 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.