ignace
Moderators-
Posts
6,457 -
Joined
-
Last visited
-
Days Won
26
Everything posted by ignace
-
objnoob is on to the right idea. function setSettingsForBrand($brand) { switch ($brand) { case 'intel': setIntelSettings(); break; default: setDefaultSettings(); break; } }So in the case of where you have a brand with no corresponding function, or misspelled the brand name, your application wouldn't error out but instead simply apply the default. Magic is cool, but not in your code. Because in the end it will pull it's greatest trick on you.
-
create a free PHP "almost" discussion mailing list
ignace replied to shengchieh's topic in Applications
PHP can handle incoming mai. -
Yes, but if you want to specify the third parameter, you'll also have to specify the second one.
-
Simply use intval $string = "<214.27080, 204.10100, 2500.51300>"; //Convert string into array - splitting on the commas $parts = explode(',', $string); //Iterate over each value in the array foreach($parts as &$part) { //Trim spaces and "<>" from each value and return the rounded down value $part = intval(trim($part, " <>")); } //Convert the parts of the array to a string using '/' as delimiter $newstring = implode('/', $parts);
-
That's because you need to specify the third parameter. mkdir mkdir($dir, 0777, true);
-
Need an critic opinion on my Autoloader Class
ignace replied to criostage's topic in PHP Coding Help
When you include composer in your project, it automatically loads all files and functions for you. No need to write your own variation. -
Turn on error_reporting, your hosting does not support curl. error_reporting(-1); ini_set('display_errors', 1);At the top of your script.
-
echo ${'Text' . $random_number};
-
$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "http://api.worldoftanks.eu/2.0/account/info/?application_id=d0a293dc77667c9328783d489c8cef73&account_id=509662813"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $json = json_decode($output); echo $json->data->{'509662813'}->statistics->all->battles;Prints: 2579 Try it here: http://phpcodepad.com/
-
echo $json->data->{'509662813'}->statistics->all->battles;
-
Every class should have a single responsibility, forcing the responsibilities of Order onto Input means it is doing work it shouldn't have to. It also makes it harder for future developers working on your project to continue development due to classes having responsibilities that they are not aware of. Which is why it's best to make your model as explicit as possible. And Order is a better name (since the customer orders a product by placing it into his basket) then Input. Just like you would have a Product class instead of naming it Input as well. Input is better suited for all incoming request data. So that you can do: $input->get('product_id'); $input->post('product_id'); // etcNot to represent an Order or Product.
- 6 replies
-
- shopping cart
- class
-
(and 2 more)
Tagged with:
-
You would learn the changes since you left at the same place you frequented as an advanced PHP developer: php.net: migrating from 5.2 to 5.3 Just follow this all the way up to 5.5 and you'll be up-to-speed in no time.
-
What is it exactly that you expect here? That we simply develop the website for you, and you get the money? Are you really that naive or simply that stupid?
-
They take the .torrent files and download them from their servers, in a queue table, search for PHP torrent download. The place where they store the downloaded files is shown to the user along with the status of the download.
- 4 replies
-
- zbigz.com/furk.net using php
- torrent caching
-
(and 3 more)
Tagged with:
-
When you have something like this, a bunch of classes and some functionality, and you don't know where to put it, you need to analyse your model and try to find missing components. In your case, you are missing Order. Your Customer Orders a Product by placing it into his Cart. $order = new Order($someProduct, 12); $cart->add($order);
- 6 replies
-
- shopping cart
- class
-
(and 2 more)
Tagged with:
-
Best way to test my PHP code for inefficiency?
ignace replied to njdubois's topic in PHP Coding Help
If you can run your code locally, you can use these tools to analyze your code: http://phpqatools.org/ Install xdebug and enable profiling, go through your application and it'll show you how long each call took and how often they are called. You need WebGrind or something similar to view the profiler output. Perhaps you have a function that is called many times, simply caching it's results will speed up your website. function simple_cache_example($foo) { static $cache = array(); if (isset($cache[$foo])) { return $cache[$foo]; // already calculated } // do calculation $cache[$foo] = $calculated; }Enable the query log and set it to table. Go over your application and view the executed queries in mysql.general_log, perhaps you'll see that one query is executed several times though it's result does not change: SELECT .. FROM some_table WHERE something = 'this'; .. SELECT .. FROM some_table WHERE something = 'this'; .. SELECT .. FROM some_table WHERE something = 'this'; .. SELECT .. FROM some_table WHERE something = 'this';Cache the result from the query as shown in the above function. Same for simple variations: SELECT .. FROM some_table WHERE something = 'this'; .. SELECT .. FROM some_table WHERE something = 'that'; .. SELECT .. FROM some_table WHERE something = 'there'; .. SELECT .. FROM some_table WHERE something = 'maybe';Simply combine it and return the correct result on each consecutive call: SELECT .. FROM some_table WHERE something IN('this', 'that', 'there', 'maybe'); .. if ($cache[$what]) { .. }You may not have these tools available due to the shared hosting. APC: Caches the PHP opcode, so your scripts no longer have to be 'compiled' between requests. It can also be used to cache your own data, like large result sets. apc_store apc_fetch Varnish: Caches your website pages and thus reduces hits to your database. For pages with partial dynamic content you can use edge side includes which are fetched by varnish and placed ad-hoc. https://www.varnish-cache.org/trac/wiki/ESIfeatures This is simply scratching the surface of the things you can do to speed up your application/website. -
LOL. You don't reject a browser simply because it doesn't properly renders your website. These are not the dark ages of webdevelopment where it was common to give a preference for a specific browser and version. Your website should display properly in IE8+, Chrome, Firefox, Safari, etc.. If it doesn't you need to change your CSS.
-
Well perhaps you should put in some effort and actually do what SocialCloud told you to do. What he said is correct, but you have failed to apply it. You can not use session_start() after sending output to the browser. All the HTML above <?php is output. Turn on error_reporting with: error_reporting(-1); ini_set('display_errors', 1);And write your PHP first, your HTML second as in: <?php session_start(); error_reporting(-1); ini_set('display_errors', 1); // PHP code here ?> HTML code here (yes that is <!DOCTYPE ..><html> and everything)Do not use session_is_registered() or session_register() but instead use the global variable $_SESSION. Stop following the tutorial you are reading, it's outdated. To check if a session variable has been registered: if (isset($_SESSION['is-this-here'])) { // yes it is } // to create session variables $_SESSION['i-am-persisted'] = true;
-
I think the design is outdated. Look at the website of the company I work for: http://www.statik.be It's minimalistic yet very modern. And shows-off some recent technologies to make the page more dynamic while impressing our clients.
-
Simply removing them is not sufficient. You need to change your FTP credentials and try to track down how they were placed on your server and fix it.
-
You'd do best to remove these files asap. They are used to mail (spam) from your server and it allows them to send arbitrary cmd's to your server. In the order of # rm -rf /
-
if (totalItems <= 35) { return 49; }is wrong and should probably be: if (totalItems <= 35) { return (totalItems / 35) * 49; }but i don't know the exact requirements, so don't simply copy/paste this and think about how it is written and correct where necessary. It is not because someone on the internet gave you a working example that is the be all and end all of it. People make mistake, those on the internet do it even more.
-
No. I had already updated my code above. Here's a demo: http://jsfiddle.net/MKVR3/1/
-
One way you could do it is, you create a new function that fills out the other fields in your form: function updatePricesOnClick(form) { form.pricePerUnit.value = calculatePricePerUnit(form.totalItems.value); form.price.value = calculatePrice(form.totalItems.value); }Your form would then look like: <form action="#"> <input type="text" name="totalItems" id="totalItems"> <input type="text" name="pricePerUnit" id="pricePerUnit"> <input type="text" name="price" id="price"> <input type="submit" onclick="updatePricesOnClick(this.parentElement); return false;"> </form>When you fill out the first field and press submit the other fields will be filled in. When you write code in the future make sure you separate the code that does calculations (or other app-related heavy-lifting like querying a database) and the code that displays things on the screen. Developers call this "separation of concern". EDIT: de-VB'ed it.
-
function calculatePrice(totalItems) { if (totalItems < 1) { return 0; } if (totalItems <= 35) { return 49; } // we have more then 35 items // the first 35 go for 49 pound // all others (totalItems - 35) go for 0.85 return 49 + (totalItems - 35) * 0.85; } function calculatePricePerUnit(totalItems) { return (calculatePrice(totalItems) / totalItems).toFixed(2); } calculatePrice(35); // 49 calculatePrice(36); // 49.85 calculatePrice(400); // 359.25 calculatePricePerUnit(400); // 0.90EDIT: apparently I misinterpreted