Daniel0
Staff Alumni-
Posts
11,885 -
Joined
-
Last visited
Everything posted by Daniel0
-
Isn't that pretty much a paraphrase of this post?
-
[SOLVED] require() reports fatal error, althought the file exists.
Daniel0 replied to ZeroError's topic in PHP Coding Help
Hmm... in that case it should be an array. Try var_dump'ing it within the if just to make sure. -
[SOLVED] require() reports fatal error, althought the file exists.
Daniel0 replied to ZeroError's topic in PHP Coding Help
Well, have you checked that $settings['quotes'] actually is an array? -
Why exactly is it you don't just pass variables by argument?
-
If you know for sure that you are going to have to use Python in the future, but don't otherwise have plans with the other languages, then I think the choice is a no-brainer (unless your AI course simultaneously teaches Python).
-
I don't know how your script looks, but global will only import things from the global namespace, not from the local namespace where the function was called. So something like this will not work: <?php function foo() { global $bar; echo $bar; } function bar() { $bar = 'foo'; foo(); } bar();
-
Have you setup an SMTP server/MTA on your server?
-
Which is precisely why it's bad practice. You have no real control over what writes to it when, and it's a pain to debug. I suppose you can always step through the code execution manually until you figure out what resets it.
-
I've never played any type of MMORPG, but I'm planning to at least check out SWTOR when it's released some time next year. That's only because KOTOR I and KOTOR II (both were single player RPGs) were awesome though.
-
It works for me. You're not calling the function in the code you posted though.
-
That's what happens when you pollute the global namespace, and it's in particular why using global variables is bad practice. Great, now I have a case study to show people when I say this
-
Okay, so this algorithm is much better: <?php function verifyAnagram(array $words, array $chars) { $numChars = count($chars); sort($chars); for ($i = 0, $num = count($words); $i < $num; ++$i) { if (strlen($words[$i]) === $numChars) { $c = str_split($words[$i]); sort($c); if ($c !== $chars) { unset($words[$i]); } } else { unset($words[$i]); } } sort($words); // to restore array keys return $words; } var_dump(verifyAnagram(array('car', 'truck', 'house', 'red', 'color'), array('c', 'k', 'r', 'u', 't'))); It'll return all words that can be generated using the characters.
-
You can generate all the permutations like this: <?php function generatePermutations(array $chars) { $numChars = count($chars); if ($numChars == 1) { return $chars; } $permutations = array(); for ($i = 0; $i < $numChars; ++$i) { $orig = $chars; $first = $chars[$i]; array_splice($chars, $i, 1); // why the hell can't it just return my new array?! foreach (generatePermutations($chars) as $str) { $permutations[] = $first . $str; } $chars = $orig; } return $permutations; } var_dump(generatePermutations(array('c', 'k', 'r', 'u', 't'))); Then you can check if the word is part of the permutations. You could also modify the algorithm to stop when the permutation has been found. Note that this algorithm is Θ(n!) (we also say that it's running in factorial time), i.e. it quickly becomes slow if you have a lot of characters. For just 10 characters there will be 3628800 different permutations.
-
2003 - Can't connect to MySQL server on 'localhost' (10061)
Daniel0 replied to mraza's topic in MySQL Help
Right, these things are irrelevant. Try checking if sessions work for other things than phpmyadmin. In that way we'll know if it's a problem with your PHP setup, or if it's a problem specifically with phpmyadmin. -
2003 - Can't connect to MySQL server on 'localhost' (10061)
Daniel0 replied to mraza's topic in MySQL Help
Does sessions work for other pages? -
There is nothing "special" about about Python. One of the important things is knowing when to use what tool. A lot of shell scripting is made in e.g. Python, and I think Gentoo's portage system is written using Python for instance.
-
2003 - Can't connect to MySQL server on 'localhost' (10061)
Daniel0 replied to mraza's topic in MySQL Help
So, does it still fail or does it work now? -
Using mod_rewrite, you can do this: RewriteCond %{HTTPS} off RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
-
It's a regular expression matching HTML anchor tags that will extract the HREF and TITLE attributes as well as the anchor text.
-
Hmm... well, do you understand what it means to return a value from a function? The ternary statement will return something based on the truth value of $row[4], and the function will then return whatever the ternary statement returns.
-
2003 - Can't connect to MySQL server on 'localhost' (10061)
Daniel0 replied to mraza's topic in MySQL Help
Hmm... try making sure that the session save path is readable by the webserver. Sessions are by default stored on the file system, so if PHP cannot write to that directory, sessions won't work. -
Notice: Undefined index: HTTPS in H:\...\slideshow.php on line 17
Daniel0 replied to killermark91's topic in PHP Coding Help
Well, the slideshow is made in Flash, so I couldn't possibly tell you. A typical way of centering a block element is to give it a width and then set the left and right margin to auto. -
Because echo doesn't return any value. You'd just want to do this: return ($row[4]) ? sprintf($html, $row[3], htmlentities( $row[1] ) ) : "hello";
-
Simple program to copy files between two computers over the web
Daniel0 replied to tibberous's topic in Miscellaneous
scp