Jump to content

intellix

Members
  • Posts

    76
  • Joined

  • Last visited

    Never

About intellix

  • Birthday 04/09/1988

Contact Methods

  • MSN
    domwatson@live.co.uk
  • Website URL
    http://www.konoro.org/online-war-games.php

Profile Information

  • Gender
    Male
  • Location
    United Kingdom

intellix's Achievements

Member

Member (2/5)

0

Reputation

  1. Managed to get this solved I originally came across a solution using a static object and another method but was given a much better solution by a guy named Ryano from Stackoverflow... I will post his solution (I won't include mine as I don't want others to use bad code) class resources { private $string; public function __construct ($string) { $this->string = $string; } public static function getString ($string) { $obj = new resources($string); return $obj; } public function replace ($replace_this, $with_this) { # Replace and return instance $this->string = str_replace($replace_this, $with_this, $this->string); return $this; } public function show () { # Return String return $this->string; } }
  2. class resources{ private static $instance, $string; public static function getString($stringName){ # Create new instance self::$instance = new self; # Grabs stringName from an XML file self::$string = $stringName; # Return instance var_dump(self::$instance); return self::$instance; } public static function replace($replace_this, $with_this){ # Replace and return instance self::$string = str_replace($replace_this, $with_this, self::$string); return self::$instance; } public static function show(){ # Return String return self::$string; } } echo resources::getString("alpha") // alpha ->replace("lpha","bravo") // abravo ->replace("vo", resources::getString("charlie")->show()) // should be abracharlie ->show(); // charlie This is the closest I thought I had got... but the original value gets replaced with 'charlie' instead of maintaining 'abravo' and replacing part of that... So close yet so far away!
  3. Hi, thanks for the reply I've had a look through the code that you've posted and read into lazy initialisation and it sounds like what I'm trying to figure out. You process the string as many times as you need to and then at the end you display the item. I got a little closer to solving this at work but forgot to send it home to have another play so will try and mimic what I had created. I basically set it so that every call of getString created a new instance of the object so they were all unique but I had this problem... The first time it would allow a replace and would use its own object, but the next time I try it, it reused the first object like so: Object resources [1] Object resources [2] Object resources [1] The code you posted here works until you try and replace a string with something else from the XML file Heres the original: #Use-Case 2 $resources->getString()->show(); // whatever $resources->getString()->replace('whatever', 'whichever')->replace('whichever', 'what-eva')->show(); // what-eva And what doesn't seem to work when you try to replace using something else from the XML: #Use-Case 2 $resources->getString()->show(); // whatever $resources->getString()->replace('whatever', 'whichever')->replace('whichever', $resources->getString()->show())->show(); // should display "whatever" again The reason I wanted to chain was to make it really easy to replace strings one after the other: $string1.replace("blah","hello").replace("name","randomer").replace("what","is meant"); Otherwise you have loads of wrapping and it gets really ugly: str_replace("what","is meant", str_replace("name","randomer",str_replace("blah", "hello", $string1)));
  4. What I'm trying to replicate is like something in Java... resources.getString("blahblah").replace("this","that").replace("that",resources.getString("anotherstring")); Each resources thing is contained as its own thing but you don't need to initiate each one of them so that its all chained and on one line and really clean. If anyone understands?
  5. Nope... didn't work and I'm still stuck
  6. I'm guessing that I need to create the opposite of a Singleton class... Like so: function getInstance(){ // If not created yet, create it and return if (self::$instance){ self::$instance = new resources(); } return self::$resources; } Will test and relay my results back here for future reference if it fixes or doesn't work
  7. Hey, I'm having a little trouble with chaining and I can't quite understand why this is behaving like it is... it's probably obvious to anyone but myself getString() retrieves the string and returns the entire object (for chaining), show() will output it as a String (so that I can do other stuff to the string first) Here it is in it's basic form: $resources->getString("newsletter.hello")->show(); // returns "Hello Name" Then lets say I want to replace some text within that string... $resources->getString("newsletter.hello")->replace("name","Bob")->show(); // returns "Hello Bob" Now...... I want to replace some text within that string with another string I get using that object: $resources->getString("newsletter.hello")->replace("name", $resources->getString("admin.name")->show())->show(); // returns "Bob" (instead of "Hello Admin") Within the first call, it grabs "Hello name" but when it gets to the second call, it replaces "Hello name" with just "Bob" because it overrides the entire string with what the second call pulls back. I need to understand why the first item gets it's value replaced (I'm guessing its because its reusing the same object so the Variable gets replaced rather than maintaining it for when I need to replace something within it) but I'm not sure how to fix it. The class (stripped out crap so its easier to read): class resources{ private $currentLocale = "en"; private $string = ""; public function __construct($currentLocale){ $this->currentLocale = $currentLocale; } public function getString($stringName){ # Grabs stringName from an XML file $this->string = xmlfile($stringName); return $this; } function replace($replace_this, $with_this){ $this->string = preg_replace("/" . $replace_this . "/", $with_this, $this->string); return $this; } function show(){ return $this->string; } } I'd really appreciate the help, I'm looking to understand this issue...
  8. I doubt the next version will be anything impressive. How often do Adobe change anything in their products before adding a new number and selling it for the same price as the previous versions?
  9. Hey guys... I have a function that allows a user to alter the size of a <canvas> element that contains an image. In order for it to resize properly I had to remove the old element and create the other, using the same image. Each image only has transparent and one other colour. Is it possible to just..... getColours on the <canvas> image and apply it to the new one? Thanks, Dom
  10. Cracked it. return $img within addCanvas and then $img = addCanvas $($img).load(function(){ // do stuff }); Can't use = onload again though as its already been added as a trigger function so overwrites the first one
  11. Edit: after re-thinking and reading my post: Short question is: how do you add an Event listener on the img loading inside a canvas? $("canvas img") doesn't work for example... Hey guys, using jQuery and JavaScript... I have a function that adds a line, when this line is added, another function is run that adds a Canvas and loads an image within it like so: Within addCanvas an image is loaded and I can trigger a function upon the image loading.. Cool. But how do I get the previous function to know when this image is loaded? I tried adding return true; within addCanvas and then in the previous function doing an if(addCanvas()){ } but it seems to get to that line and if the image hasn't loaded, it doesn't wait function addText(){ // Add text code addCanvas(); } function addCanvas(){ // add canvas, load image var $img = new Image(); $img.src = 'image.png'; $img.onload = function(){ // do stuff } } I wanted the previous function to know when it has loaded so I can continue with all the variables I currently have... If I can't check for it in the previous function then I'll have to pass them all when they're only needed in certain conditions and its a little messy. It's a canvas but can't really do $("canvas").load(function(){ // loaded }); because the canvas is already loaded... its the image inside it I want to check that has loaded
  12. Hey guys, creating an autocomplete function for something and I'm hit with problems of case sensitivity... At work we have a language file for different languages like: English, Swedish, Russian, Turkish, Greek; etc and I was under the impression that to support all of these languages and for future compatibility, all my databases needed to be UTF8 like the language file at work. So I'm using UTF8-BIN Now it comes to this, I read the Mysql document and BIN is a case sensitive collation? It looks like I have to convert it on the fly to a case-insensitive collation but I don't see the point in that? Surely it should just be an insensitive collation from the start? What would you recommend? How does this work with other character sets? I'm looking here at: utf8_bin utf8_general_ci After reading a little I guess what I want is utf8_general_ci as I want a bit of flexibility for string comparisons. Is there a difference in performance at all? Thanks, Dom
  13. I use Netbeans because I like the clean interface (in comparison to Eclipse) and everything seems to just work, like xDebug integration etc. Theres also stuff like database connecting to it but I have still to find out what the point of it is... lol I used to use Notepad++ but when you want to debug and profile, it just doesn't cut it. I also like how it helps highlight code mistakes...
  14. Thanks for the bug report That page is about 1 year old and haven't changed it since changing alot of the database so have fixed it now I'll check out deviantart.com and conceptart.org to see what kind of stuff I can find Thanks
  15. I guess I'll do that, just wanted to know what the quickest method is really. Thought it would have been to createElement... maybe i'll do that and remove the UL (probably quicker?) lets see
×
×
  • 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.