Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. @barand sorry, my apologies, that was a response to thara, it just was posted with a bad timing apparently IPB does not always report when new content was added and I didn't check due to this handy feature.
  2. That is because your function/calculation is wrong. @kicken and I just pointed out to get the X months Y weeks Z days .. you needed to concatenate the results. The correct calculation goes something like: function time_elapsed_since($postedDateTime) { $diff = abs(time() - strtotime($postedDateTime)); // to get the time since that moment $years = (int) $years = $diff / 31536000; $months = (int) $months = ($diff % 31536000) / 2592000; $weeks = (int) $weeks = (($diff % 31536000) % 2592000) / 604800; $days = (int) $days = ((($diff % 31536000) % 2592000) % 604800) / 86400; $hours = (int) $hours = (((($diff % 31536000) % 2592000) % 604800) % 86400) / 3600; $minutes = (int) $minutes = ((((($diff % 31536000) % 2592000) % 604800) % 86400) % 3600) / 60; $seconds = (int) $seconds = (((((($diff % 31536000) % 2592000) % 604800) % 86400) % 3600) % 60); return ($years ? $years .' years ' : ''). ($months ? $months .' months ' : ''). ($weeks ? $weeks .' weeks ' : ''). ($days ? $days .' days ' : ''). ($hours ? $hours .' hours ' : ''). ($minutes ? $minutes .' minutes ' : ''). ($seconds ? $seconds .' seconds ' : ''); } The very verbose format can be shortened. Something like: echo time_elapsed_since('+9876 minutes'); Returns: 6 days 20 hours 36 minutes Much easier is it of course to simply: $diff = new DateTime(new DateTime('+9876 minutes')); Which returns a DateInterval and has several properties to get the number of seconds/minutes/hours/.. http://php.net/manual/en/class.dateinterval.php Or use Carbon: echo (new Carbon)->diffForHumans(new Carbon('+9876 minutes'));
  3. Like @kicken mentioned, don't return early and concatenate the results. $str = ''; foreach ($tokens as $unit => $text) { if ($time < $unit) continue; $numberOfUnits = floor($time / $unit); $str .= $numberOfUnits.' '.$text.(($numberOfUnits>1)?'s':''); } return $str;
  4. What are the relations between both tables? Like does a product have multiple reference_number's? Or just one? What is meant with capacity? .. Please provide all information. IMO EAV is not the answer here. When I look at the (partial) design I feel that not all tables/relations have yet been identified and thus causes confusion. Identify all tables and their relations to make the model speak out and clear up the confusion. EDIT: Maybe some of these options solve your problem (except EAV, check comments below): http://stackoverflow.com/a/695860
  5. Chances are that $this->dire points to a directory without a trailing slash. Make sure it has a trailing slash and try again.
  6. CF already showed you how. As you can see he populates $this->error with the exact error message. To display it simply: if ($myClass->error) { echo $myClass->error; } A few frameworks provide classes that you can use to do these tidy tasks for you, for example Zend has a Transfer object to download or upload a file. An off-the-bat example would be: namespace MyApp; use Zend\File\Transfer\Transfer; class FileUploadService { const UPLOAD_FILE = 'file'; const UPLOAD_IMAGE = 'image'; public function phpFilesArrayUpload($name, $destination, $type = self::UPLOAD_FILE) { if (!is_string($name)) { throw new InvalidArgumentException(__CLASS__ ."::". __METHOD__ ." expected a string, got ". gettype($name)); } if (!isset($_FILES[$name])) { throw new InvalidArgumentException("Invalid upload name '$name' specified"); } try { $transfer = new Transfer(); $transfer->setDestination($destination); if ($type === self::UPLOAD_FILE) { //$transfer->setValidator(); .. } else if ($type === self::UPLOAD_IMAGE) { //$transfer->setValidator(); .. } return $transfer->receive($_FILES[$name]); } catch (Exception $e) { throw new DomainException($e->getMessage(), 0, $e); } } } Usage would be like this: try { $service = new FileUploadService(); $service->phpFilesArrayUpload('img_Up', 'path/to/upload/to', $service::UPLOAD_IMAGE); } catch (Exception $e) { echo $e->getMessage(); }
  7. It's also best to avoid global variables as much as possible. For example because PHP does not have a main() method but it does have an index.php which is auto called it is common to find a Bootstrap class in there. require '../libs/MyApp/Bootstrap.php'; (new Bootstrap)->init(); Inside the init() method you have your bootstrapping code. init() self is a template method. $this->initConfig() ->initDb() ->initFoo() ->initBar();
  8. It will work when included. require 'Query.php'; $query->foo(); Another way of achieving this is at the end of Query.php (replacing the current last line) you write return new Query(); Then in your main: $query = require 'Query.php'; I must mention though that it is considered bad practice to create an instance at the end of your files. Much better is: require 'Query.php'; $query = new Query(); Because in these simple examples this works, but in bigger projects multiple instances have to be created which would result in "Cannot redeclare existing class Query" which would mean additional code would have to be wrapped around your class. Not to mention that most projects use autoloading and your instances would not even be in a global context but in the autoloader's and you would have no way to access those variables. To give an example of such an autoloader: spl_autoload_register(function($className) { $className = ltrim($className, '\\'); $fileName = ''; $namespace = ''; if ($lastNsPos = strripos($className, '\\')) { $namespace = substr($className, 0, $lastNsPos); $className = substr($className, $lastNsPos + 1); $fileName = str_replace('\\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR; } $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php'; require $fileName; }); $query = new Query(); As you can see the require() call is made in the autoloader and not available to you in the global context.
  9. How is this different from Gearman? Just do it, you asked now twice without any response. You'll figure out soon enough wether it was ok.
  10. Well a cat licks itself clean so it's possible some of that bleach has ended up in her mouth too, even more when you used the real 404 cleaner. So yeah it IS your fault. Yeah because those are totally harmless. Why don't you try and drink it ad fundum since they are so harmless? Don't try to make yourself feel any better telling yourself that it wasn't your fault. Because IT IS. The only reason you are on this forum talking bullshit, hoping someone here is gonna tell you it is not your fault, instead of going to the vet, because you are afraid that when you go to a vet he will find out what you did and call the animal protection unit. If a cat poops and shits everywhere it means it's not been trained properly. We have a cat box and our cat always does her business in there. And how old are you anyway? Maybe you should move out and get a place for yourself and away from those cats. Probably not the first cat you killed, and by the looks of it not the last one either.
  11. Apparently they are going to do a reboot, nice FU to all those haters. They are going to call it: NotRuby. PS: and they are going to make all arguments of all functions/methods random (optional becomes mandatory, and more fun stuff like that).
  12. I must mention that the above code uses normalize.css. Using a <link> tag.
  13. In_array already qupports a third argument.
  14. I was bored, so I created this (10 minutes or so): http://jsfiddle.net/WV8R8/ Though you will have to convert it to a percentage based design or it will be tiny on that 50" screen. The colors were taken from: http://147colors.com/
  15. $lottery_numbers = array(1413,1812,2325,2326,2623,3236,3738,3932,5156,6169); $user_numbers = array(2326,3236); $matches = array_filter($lottery_numbers, function($lottery_number) use ($user_numbers) { return in_array($lottery_number, $user_numbers); }); switch (count($matches)) { case 2: if (is_consec($matches)) { // consecutive } else { // not } break; case 4: if (is_consec($matches)) { // consecutive } else { // not } break; default: // nada! break; } function is_consec($array) { $lastKey = null; foreach ($array as $key => $value) { if (!is_int($key)) { if ($lastKey !== null) { return false; } continue; } if ($lastKey === null) { $lastKey = $key; } else if (abs($key - $lastKey) !== 1) { return false; } } return true; }
  16. Execute htmlentities against your description before inserting it into the XML.
  17. ezSQL is a big no-no IMO since it coded against PHP4. NotORM is a much better alternative since it has been coded against 5.x+ and actually has automated tests though it's over 2 years old and has 14 open issues... Maybe the Zend\Db component is something for you? https://github.com/zendframework/zf2/tree/master/library/Zend/Db/Adapter/Driver/Pdo What kind of extensions built on top of PDO are you looking for? QueryObject?
  18. ROFLMAO. PHP is just fine. You send HTML to the browser, so search engines will also read that HTML not your PHP script. Like thorpe mentioned you need mod_rewrite to create rewrite rules so special URL's are re-routed: http://somedomain.top/blog/foo-bar-was-here/ Which is then redirected to your script where you resolve foo-bar-was-here to an actual row in your database and display that information.
  19. The same goes for the currency symbol it's not that simple that it is always at the front. Since it revolves around scraping ("which will get all price information on a page.") the symbol might aswell be at the end, it might not even be a symbol just the abbreviation (eg EUR). Since NASA is upping it's efforts maybe to make it complete we should assume that in the near future an alien civilization may enter our solar system and have a different formatting all together, we should account for that too.
  20. The OP did not mention he needed that. And if he does want it that is easily fixed by swapping the . and , You mean like $123456 ? It only matches $123. Can you give an example?
  21. If you also want to match negative or positive values: $value = '/'. preg_quote($currency) .'\s?[-+]?(\d{1,3}(,\d{3})+|\d{1,3})(\.\d{2,})?/';
  22. $value = '/'. preg_quote($currency) .'\s?(\d{1,3}(,\d{3})+|\d{1,3})(\.\d{2,})?/'; You can try it yourself here: http://refiddle.com/4xr
×
×
  • 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.