Jump to content

genericnumber1

Members
  • Posts

    1,858
  • Joined

  • Last visited

    Never

Everything posted by genericnumber1

  1. If you look at his code, it doesn't seem to be in an algebraic form. He appears to have the values of x and y and wishes to just plug them into the formula and evaluate it - all completely doable with eval (again, if you want to use eval).
  2. There are many ways of doing what you're explaining. The simplest is just to use eval, but I won't say whether or not using eval is a good thing, because there are strong feelings both for and against it. If you want some other methods, google "parsing a string as a mathematical equation" (or math parser or mathematic expression evaluator, etc), it should give you a good starting point (though not necessarily a php one) if you wish to learn about how to avoid using eval and to help yourself answer the question whether it's worth all of the trouble to avoid the function.
  3. You might want to google around a bit for form handling with php, and once you get that hammered down, ask about any specific problems you might have with implementing what you're explaining.
  4. I tend to stick with these forums, as others have stated, to try out problems I haven't tried before. All of the problems proposed by classes and books are full of academic types of problems and they get stale fairly fast (You can only make so many calculators before you want to hang yourself). There are, on occasion, some fun to answer questions on this board beyond the boilerplate stuff I'm used to doing. In addition, also along with what someone else said, I don't get to do PHP beyond some personal quick scripts and the like since all of my other programming is done with different technologies. I love PHP, so I have to come here to get to write some code.
  5. "192.168.151.35" is the form for a local address as you said, and I receive the same ip address listing when I visit your website. If the request goes through a router, the remote address could be the router's address. Try to find a setting in your router that specifies whether it passes along the IP of the person who made the request. If it's not the router's fault, try figuring out which computer on your network this IP belongs to.
  6. Do note that other people gave the same solution before me. I just explained my best guess as to why you need to do it this way.
  7. I'd imagine it was more useful in php4 when all classes weren't passed by reference automatically. Although I suppose it could be useful to retrieve references to certain array elements so that they can be modified. Something like... <?php function &findValue(&$array, $search, &$found = false) { foreach($array as &$valRef) { if($valRef == $search) { $found = true; $result =& $valRef; break; } elseif(is_array($valRef)) { $result =& findValue($valRef, $search, $found); if($found) break; } } if($found) { return $result; } else { return $found; } } $array = array( 'Hello', 'World', array( 'DeeperHello', 'DeeperWorld' ) ); $result =& findValue($array, 'DeeperHello', $found); if($found) { $result = 'ModifiedDeeperHello'; } print_r($array); /* Array ( [0] => Hello [1] => World [2] => Array ( [0] => ModifiedDeeperHello [1] => DeeperWorld ) ) */ Of course it's messy, but you get the idea. I haven't used it before, but you never know.
  8. This took me a while to figure this one out, What I THINK is happening is this.. when $value = 0, $value < 301 is returning true and $value > 300 is returning false, so the switch statement ends up like this... <?php $value = 0; switch ($value) { case true: echo "less than 301"; break; case false: echo "greater than 300"; break; } But 0 is another way of saying "false" (every other non-zero integer is true), so it ends up following the false case because as far as php is concerned $value is false, so it matches the case conditional. Do this.. <?php $value = 0; switch (true) { case ($value < 301): echo "less than 301"; break; case ($value > 300): echo "greater than 300"; break; } And everything should function as expected Edit: just explaining the reason you need to put true instead of $value
  9. Return a reference. <?php function &testFunction(&$testReference) { return $testReference; } $test = 'hello'; $reference =& testFunction($test); $reference = 'world'; echo $test . ' ' . $reference; The above code does not output "hello world", it outputs "world world" because testFunction returned a reference to $test. It doesn't appear particularly useful in this circumstance, but it can be quite useful in some situations.
  10. Yes. http://us.php.net/variables.scope But you shouldn't..
  11. The reason you want a CAPTCHA is so that it's much more difficult to create a program to automatically enter your form, if it's the same image every time there isn't a reason to even have one.
  12. Jimbo, like it has been stated numerous times notepad++ is a text editor, it doesn't have a built in browser or the ability to execute php, it only has the ability to modify text, hence it being called a text editor. You'll need to have one window with notepad++ where you edit your code, and a second web browser window opened to your localhost. There's no way to execute PHP in notepad++, it's all done by your server (Xampp) and the resulting html is rendered in your web browser.
  13. Unexpected end typically means there's an unbalanced set of brackets in your code (ie. more { than }) although it could mean other things. It's basically php's way of saying "wait, you weren't done saying something to me, I wasn't ready for you to stop," perhaps the computing equivalent of telling PHP a really elaborate joke and stopping before the punchline, disappointing PHP and causing it to throw a hissy fit and hold its breath until you finish what you started.
  14. It's really messy, I'm afraid it's too late and I've had too long of a day to make myself bite the bullet and try to guess what's going on. It looks like you have that else a few lines up as well as at the position it's causing the error.
  15. Erm.. <?php $date_start = $row['date_start']; $date_start_converted = ""; if (!empty($date_start)) { $date_end = $row['date_end']; $date_start_converted = date("M jS, Y", strtotime($date_start)); $date_end_converted = date("M jS, Y", strtotime($date_end)); } ?
  16. This code is incredibly messy.. when auto-indentation can't clear much up you know you need to refactor. That else isn't expected because it's outside of the function, localizing the problem you have... <?php function HandleOutstandingSendSuccesses ($user) { // ... } else { // ...
  17. Like I said twice, quite nicely I might add, just pass it into the class at instantiation (like DJ just gave an example of) or pass it into the function when you call it. Global variables are evil, at least encapsulate them in a singleton if you insist on using global state. Example of passing them to a function: <?php class TestClass { function testFunction($snoopy){ $snoopy->action(); } } $snoopy =& new Snoopy(); $testClass =& new TestClass(); $testClass->testFunction($snoopy); I didn't think I'd need to show you HOW to do it because it's quite simple. If this Snoopy class does indeed maintain state, you may want the class to have its own instance like Dj suggested instead of passing it to the function.
  18. The reason it doesn't work is because $snoopy isn't defined, you'll need to pass the instance into the function either when you call it or you can pass it to the class when you instantiate it. Those are the two simplest methods.
  19. There are numerous ways of doing this, the easiest of which is just to pass the instance of the class into the function. You could also pass it to the class in the constructor, build a singleton so you can retrieve the instance without passing it to the class in either the function or the constructor, etc. There's really no way to "tell you how to fix it" because how you will fix it depends upon what this snoopy class is, what its state is, what its function is, etc.
  20. To clean up yours: <?php foreach($array as &$value) { $value = implode('-', $value); } $mapStr = implode('_', $array); To do the opposite: <?php $array = explode('_', $mapStr); foreach($array as &$value) { $value = explode('-', $value); } There are shorter ways of doing it, but this is the cleanest I can think of. The best way to break down an array into a string though is to use serialize.
  21. I'm not sure what you mean, why would you want to print 10, break and then print 10 when you could just print 20 to begin with?
  22. You might want to look into scope with regard to object oriented programming.
×
×
  • 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.