Jump to content

silkfire

Members
  • Posts

    569
  • Joined

  • Last visited

Everything posted by silkfire

  1. UTF-8 is variable-width man, take a look here: http://en.wikipedia.org/wiki/UTF-8 But yeah, the basic question is, how do I find the position of the first multi-byte character? I've tried with some custom mb_explode function and then looped through the array but it's not so performance effective.
  2. Try this: $url = 'http://www.example.com/products/entertainment/films/dvd/page.html'; echo implode('/', array_slice(explode('/', $url), 0, -2)) . '/';
  3. Mmkay any way to do it with regex? Or what is your suggestion?
  4. You'll have to use a JOIN of some sort on a column with common values.
  5. I need a way to determine the position of the first unicode character in a string. For example, if we have '89423io3önska032j' (encoded in UTF-, I need to return number 8. None of the mb_ functions I found were suitable for this purpose. Hope someone can help me on this one. I also need the function to be performance effective, so no advanced solutions as this will be used in a loop.
  6. I would recommend you to use PDO with prepared statements, then you're 100% safe from injections of any sort.
  7. Your json is correctn, don't worry. Otherwise PHP would bail out and return an error of some sort.
  8. That doesn't solve my problem stiill....
  9. I tried to var_dump this array and the other elements start at 5, not 0 =(
  10. Can someone guide me on the most effective way of doing this? 1. I got an array where some keys have a specified numeric key. 2. I want to sort this array in such a way that those elements without a specified numeric key must get a key. If it exists, then increment. Before: array(1 => 'val1', 4 => 'valY', 'valX', 'valZ', 'valN'); After: array(0 => 'valX', 1 => 'val1', 2 => 'valZ', 3 => 'valN', 4 => 'valY'); Thanks in advance!
  11. Just a quick question. Why is $defaults static? Does it mean it will only be created once during script execution? I mean it's private too so it's not going to be accessed outside the class either.
  12. See it a bit like bitwise operations. I maybe want to copy some bits (properties, bitwise-OR), but reset others to default (negation + AND).
  13. Thanks again. This line right here doesn't make sense to me: $val = $this->defaults[$key] ?: null; Will it be null either way? Well I can't explain what exactly I'm working with but I want the object creation to use as few steps as possible. When I create an object with properties and want to create a new one but with different color and not copy its size, I want the class to automatically take care of this for me. $a = new SmallObject(); $a->color = 'red'; $a->size = 32; $a->shared = true; $a->url = 'www.example.com'; $a->country = 'DE'; ... // 6-10 more properties Instead of assigning all those properties again if I want to change country and use default color I do: $b = clone $a; $a->color = false; // Set to default value $a->country = 'US'; Or am I making this harder than it should be?
  14. For very big numbers its recommended to use the BCMath library, as Barand's example shows.
  15. Thanks for the help, ignace. I've got some questions though. 1. I had no idea you could use the keyword static as in static:: (I mean, it's not a class?) or static() (it's not a function?). What do these mean? 2. Where in your solution do I give the properties of default_object its default values? Remember that the values of default_object must be the initial values of my SmallObject upon construction. 3. By the way, I use this object so that new objects can inherit properties from an existing object. If I want to set some property to its default value I do like this: $object3->size = false; 4. Why is default_object access type protected? Can it be private? 5. In the __set function, if I forget $this->{$key} = $val;, will the value never be set, i.e. will it override/prevent default behavior?
  16. Yeah it's not very clear, but which part do you want me to explain better?
  17. I have a pretty large project now that uses quite a couple of classes. Now I've stumbled upon this problem. I have a class with properties that are public. Objects of this class are inserted into a container (which is another class). I have made so that if any of the properties are set to false (in the __set function), then the value must be reverted to the default value. The default value is taken from an object that is created in the construct (object of oneself witjin object). I think this causes an infinite recursion. What's the best way to solve this problem? This container may contain like 10 objects of my class, each of these in turn - an object with default values that is same for all. It seems unnecessary to create this object in every object. I know this sounds a bit confusing but don't know how to solve this. Also, if the container class is the one to have the default values then the object class needs to have access to it somehow, but even if that would be possible then each object would be really huge because it also contains the container?? class SmallObject() { private $default_object; function __construct() { $this->color = '#5432FA'; $this->size = 5.3; $this->default_object = new SmallObject(); } function __set($property, $value) { if ($value === false) $this->$property = $this->default_object->$property; } }
  18. So you want to retrieve all users whose birthday is within 3 days? Or within 3 weeks? Or months? Or retrieve all users that together equal at least 3 and have their birthday this month? Or this week? Kinda confused here.
  19. I tested a feature today I thought would be possible but seems it is not. I want to create an array and one of the values references a preciously created value. I like elegant code that's why I'm asking. $a = array( 'test' => 'cat1', 'nest' => 'cat66', 'gest' => $a['mest'] ); var_dump($a); One could think this will give you "Notice: undefined index mest", but it will actually say "Undefined variable $a". Any solution to this?
  20. Which of the commands gives you Permission denied, the first or the second one?
  21. Try chmoding the directory, not the file itself.
  22. Off top: I laughed really loud when I read your mispelled topic title, sounds like you're saying "Need help raping the body of my shopping cart"
  23. But if it's purely for get and set? Calling a function is overhead, right?
  24. I wonder why one should use get/set with private property when working with classes instead of creating a public variable that you can modify? $obj->testvar = 'New value'; seems easier than: private $testvar; public function setValue($new_value) { $this->testvar = $new_value; } public function getValue() { return $this->testvar; }
  25. I've been thinking about this for a while. In my classes I use self::method() for all methods, including non-static ones. Why does PHP allow this in the first place? What are best coding practices do you think? I haven't been able to find much about this by googling except for this but it didn't give me an intelligent answer. http://forums.devnetwork.net/viewtopic.php?f=1&t=113624
×
×
  • 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.