Jump to content

intellix

Members
  • Posts

    76
  • Joined

  • Last visited

    Never

Everything posted by intellix

  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
  16. Aye but I wanted it to happen all at once so however long the loop took, it all happened at once so it queues them all up and then when its finished loading them it goes in at once using html(); I did originally have $("<li></li>"); but I read somewhere that it's slower than the raw JavaScript createElement method, so wanted to make it as quick as possible and happen at once... probably not much difference in speed but wanted to have it perform as best possible
  17. Hey guys, I have a UL element, which contains aload of X co-ordinates like so: <div id="xCoords"> <ul style="left:100px;"> <li>1<li> <li>2<li> <li>3<li> </ul> </div> When something is loaded using JSON I need to replace the list containing new numbers and it needs to be quick. It works great at the moment but the problem is that in IE6/7 it works a little differently and the CSS is causing it to display funny because of the way it's being added. I'm creating an elements and then using jQuery to put it in there like so: // Create UL element var $ul_node_x = document.createElement('ul'); for (loop){ // Create LI element var $x_li = document.createElement('li'); // Add LI element to UL $ul_node_x.appendChild($x_li); } $("#xCoords ul").html($ul_node_x); What's happening is, inside IE6/7 its creating something like the code below where an extra UL is added (because I'm creating a UL element with LIs and putting it inside the first UL: <div id="xCoords"> <ul style="left:100px;"> <ul> <!-- EXTRA UL IS ADDED --> <li>1<li> <li>2<li> <li>3<li> </ul> </ul> </div> I wanted to sort of create aload of LI elements, but I think you need to create a container to put them all in, that's why I have the UL... The way I'm looking at it, I'm guessing I need to delete the first UL and put it in the <Div> container... I'm not removing all the LI elements and then appending them because I wanted the loop to finish first and then instantly place the new list to make it appear as though there's no lag... Thanks guys
  18. The look I was trying to go for from the start was a Art-stylised 'Prince of Persia' sort of thing. Where everything looks painted and textured but the problem is the guy who did the blobs isn't much of a graphic designer, hes more of an artist than digital artist I think... then the other guy who works on the buildings, canvas, game backgrounds etc is a completely different person altogether :/ He seems to want to take it his own way. Some of the graphics he creates are quite nice (I like the blue and red game backgrounds and I think some of his buildings are pretty cool) but then there are times where some of the stuff created looks like it was done drunk and its hard to understand if he has any sense of how things look at all. He gives me bit by bit of the site instead of designing the entire thing, showing me so we both agree that it's what it should look like and where it should go, then dictate to me that it needs to be pixel perfect to his design. I think at the moment the graphics pull the game down. I'd love a great graphic artist to tie everything together in one style that works. Footer text isn't really anything important I don't think
  19. Also in terms of performance... Say if I have a 250kb JSON script pulled and put into an object like: var $largeData = jsondata; Once I've done with it, do you think its good to set it to null or something to free memory? Or is this done automatically and not needed?
  20. Am I wrong to think that it's probably the worst idea ever to be able to process a client side script as PHP?
  21. Hey guys... quick question I have jQuery using JSON to pull in aload of data... Within the JSON request, when it returns data, I have a loop that adds stuff to an object and then updates the page... It uses a variable I want to update at the same time. If I make the request and I start playing with the site, I want the function at the end of the loop to use the latest data (as JSON isn't instant and I don't want to lock the page from the user updating it)... Can I update the variable whilst the JSON request, loop is running and then when it gets to the end of it, the variable will be updated? Or does JavaScript work on a queue sort of basis where it will finish the JSON request, loop first until I can start updating variables that will be used at the end of it all? Thanks, Dom
  22. Nice and tidy Perhaps could do with a bit of pizaz... not sure what. Perhaps the fancy font is overused? Can't say that I like the lightbox script currently in use... There are so many nice lightboxes and I think the one you are using is a little bit ugly with the Loading...
  23. I guess you could just look at the phpMyAdmin source cod to see how they do it. Must be the best way possible
  24. It's actually quite refreshing to hear that I was told that the only thing my application really needed was the front and backend split up using templating... I'm the only developer of the project but I'm well aware of both front and back end so to me it wasn't ever really needed... perhaps if the company was to expand rapidly then it would be worth splitting them up for 2 separate jobs? I went into the Smarty documentation expecting something magical and left quite disappointed... to me it just seemed like I was changing one syntax (PHP) to another (Smarty) for no reason, I don't quite see how this splits front and back as the front-end still contains so much page logic that even throws an exception if coded wrong... Obviously my app could do with numerous updates that removes much of the spaghetti XHTML/PHP/MySQL up
×
×
  • 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.