Jump to content

Daniel0

Staff Alumni
  • Posts

    11,885
  • Joined

  • Last visited

Everything posted by Daniel0

  1. That is overall a bad idea. A field in a database should only contain one element only. Look into database normalization.
  2. The easter egg is 'phpfreaks'. function _f($z){return($z==1?0:($z==2?1:_f($z-1)+_f($z-2)));} $_a=array(0x38,0x2d,0x3c,0x2a,0x3d,0x45,0x36,0x24,0x21,0x3c,0x2c,0x51); $_b=array(0x6f,0x66,0x6d,0x65,0x70,0x62,0x60,0x69,0x70);for($i=0,$a=sizeof($_a),$b=sizeof($_b);$i<$a;++$i)print(chr($_a[$i]^($_b[$i%$b]+_f($i%3+3)))); Here is how it works: The function I defined is a recursive implementation of the Fibonacci sequence. The arrays $_a and $_b contain the strings HELLO WORLD! and phpfreaks. However, each character in $_b has been shifted upwards with the $i % 3 + 3th Fibonacci number. Then I applied a XOR shift on $_a with the Fibonacci shifted string. The code I posted reverses this of course.
  3. I believe the rationale is that when you are capitalizing things, it becomes more important. A title is important, thus you capitalize it. I usually do not use it though.
  4. Dunno what the article says, but you'll want to use something that doesn't open and close the connection to the SMTP server constantly (like mail()) does. You might even want to put some of the mails in a queue to restrict the number of emails you send out per X units (e.g. you might only want to send out 300 emails per hour).
  5. To build onto this, something you could additionally do is give each player/monster/item a "realm", a kind of area they can act within. So imagine a circle around them with the player position in the center C(x1,y1). The radius r1 of that circle could depend on various factors. So that circle is given by (x-x1)2+(y-y1)2=r12. So, someone can interact with people within their realm, i.e. they can interact with with people whose center is within their circle (because everything else has an imaginary circle around them). This will be true if the distance between their centers is less than either of the radii. So if we have two players in P(x1,y1) and Q(x2,y2), and the player in P has realm radius r1, then the player in P can interact with the player in Q iff |PQ| < r1. Doing this you'll of course have to envision the "world" as a Cartesian coordinate system instead of tiles with integer coordinates.
  6. Yeah, but it's a special recursive function, a particular type of bit manipulation and one of the number sequences have a special meaning and one of the number sequences have a special meaning if you fiddle a bit with it.
  7. function _f($z){return($z==1?0:($z==2?1:_f($z-1)+_f($z-2)));}$_a=array(0x38,0x2d,0x3c,0x2a,0x3d,0x45,0x36,0x24,0x21,0x3c,0x2c,0x51);$_b=array(0x6f,0x66,0x6d,0x65,0x70,0x62,0x60,0x69,0x70);for($i=0,$a=sizeof($_a),$b=sizeof($_b);$i<$a;++$i)print(chr($_a[$i]^($_b[$i%$b]+_f($i%3+3)))); Ninja points to whomever finds the easter egg(s).
  8. Like this? <?php $string1 = 'Does the dog jump over the lazy sheep or the spotted cow?'; $string2 = 'The dog jumps over the lazy sheep.'; $similarities = array_intersect( explode(' ', preg_replace('#[^a-z ]#', '', strtolower($string1))), explode(' ', preg_replace('#[^a-z ]#', '', strtolower($string2))) ); $similarities = array_values($similarities); $count = count($similarities); $matches = array(); for ($i = 0; $i < $count; ++$i) { for ($x = 0, $xMax = $count - $i; $x < $xMax; ++$x) { $m = array(); for ($j = $i, $jMax = $i + $x; $j <= $jMax; ++$j) { $m[] = $similarities[$j]; } $m = join(' ', $m); if (!in_array($m, $matches)) { $matches[] = $m; } } } print_r($matches);
  9. Right, but there are several substrings that the two strings have in common. When is it enough to regard it as a match?
  10. That's a pretty complex task. "The" also appears in both of them as well and so does "the dog". Anyway, try to experiment with something like this: <?php $string1 = 'Does the dog jump over the lazy sheep or the spotted cow?'; $string2 = 'The dog jumps over the lazy sheep.'; $similarities = array_intersect( explode(' ', preg_replace('#[^a-z ]#', '', strtolower($string1))), explode(' ', preg_replace('#[^a-z ]#', '', strtolower($string2))) ); print_r($similarities); Edit: Someone beat me to it. Edit 2: Why would this not be a "similarity"? "Does the dog jump over the lazy sheep or the spotted cow?" "The dog jumps over the lazy sheep."
  11. That is easy. If you set it up like a regular Cartesian coordinate system with points (x,y) it'll be easier. So if you have two points P(x1,y1) and Q(x2,y2), the distance between them will be the length of the vector between them. So we have [tex]\overrightarrow{PQ} = \left( \begin{array}{c} x_2 - x_1 \\ y_2 - y_1 \end{array} \right)[/tex]. By the Pythagorean theorem, the length of a two dimensional vector is given by [tex]\sqrt{x^2+y^2}[/tex] where x and y are coordinates of the vector. Thus the length of our vector is [tex]|\overrightarrow{PQ}| = \sqrt{(x_2-x_1)^2 + (y_2-y_1)^2}[/tex], which is also the distance between the points P and Q. This will work for all points (x,y) in [tex]\mathbb{R}^2[/tex]. So if you have two points P(5,7) and Q(9, the distance between P and Q will be [tex]\sqrt{(9-5)^2 + (8-7)^2}=\sqrt{17}\approx4.12311[/tex].
  12. It already was. No, but you can just write it in base 8, base 10 or base 16, which PHP has a syntax for. Internally in memory any number is stored as binary regardless, so the base n expansion you use when displaying it is irrelevant.
  13. That's my point. If you enter a genuine question+answer then someone can probably guess it. If you don't then you are trying to circumvent the system. In either case it's useless.
  14. I hate "secret questions". I can't find a question and an answer that loads of people couldn't guess or otherwise figure out. I usually just enter a bogus answer, like a secondary password. I think the concept of "secret" questions are ridiculous.
  15. Never thought about it....its their fault for not having it on anyway. WHAT IF they dont anyway, whats the alternative?? http://en.wikipedia.org/wiki/Unobtrusive_Javascript http://en.wikipedia.org/wiki/Separation_of_concerns
  16. sʞɐǝɹɟdɥd
  17. Yes, you can. If something contains a $-sign, but cannot be interpreted as a variable, PHP will just ignore it and not try to substitute it.
  18. Daniel0

    Current_Date

    Then perhaps you should try posting the queries you've attempted to use and don't work. We can't really tell from "I've tried a number of different things". "Doesn't work" isn't very descriptive either. It can mean many things such as 1) unexpected result, 2) no output, 3) errors, etc. You should always tell what result you expect, what result you get and any errors that pop up.
  19. This should work: <?php error_reporting(E_ALL & ~E_DEPRECATED); ereg('foo', 'bar');
  20. You try to avoid Javascript, but use AJAX for everything else? You do realize that AJAX is a Javascript technique, right?
  21. How would it be a security risk in respect to the database?
  22. That is why OOP is better than procedural. It enables you to encapsulate things. Even then, the fact that it's not possible using procedural code without using globals doesn't mean globals are good. It could also mean that the error handling is not properly implemented in PHP. It could for instance pass the old error reporter via argument.
  23. As far as I know it only supports 1.0.
  24. By encapsulating it in an object. <?php abstract class ErrorHandler { private $_oldErrorHandler; private $_useStack = false; public function __construct($useStack = false) { $this->_oldErrorHandler = set_error_handler(array($this, 'error')); $this->enableStack($useStack); } public function enableStack($enable = true) { $this->_useStack = (bool) $enable; return $this; } public function getOldHandler() { return $this->_oldErrorHandler; } public function error($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()) { $this->_handleError($errno, $errstr, $errfile, $errline, $errcontext); if ($this->_useStack && $this->_oldErrorHandler !== null) { call_user_func_array($this->getOldHandler(), array($errno, $errstr, $errfile, $errline, $errcontext)); } } abstract protected function _handleError($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()); } class ConcreteErrorHandler extends ErrorHandler { protected function _handleError($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()) { echo 'someone screwed up: ' . $errstr . PHP_EOL; } } class AnotherHandler extends ErrorHandler { protected function _handleError($errno, $errstr, $errfile = '', $errline = 0, array $errcontext = array()) { echo 'Error: ' . $errstr . PHP_EOL; } } $handler = new ConcreteErrorHandler(); trigger_error('hello world', E_USER_WARNING); $handler2 = new AnotherHandler(true); trigger_error('hi world', E_USER_WARNING); Output: someone screwed up: hello world Error: hi world someone screwed up: hi world
  25. That's an example, yes, but how does that show that globals are a good idea?
×
×
  • 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.