-
Posts
15,229 -
Joined
-
Last visited
-
Days Won
427
Everything posted by requinix
-
Generate random numbers with in given time duration
requinix replied to Ruban_kutty's topic in PHP Coding Help
Use mt_srand to set a random number seed. This seed controls what series of random numbers you will get: same seed, same numbers. The seed you pass in should be the same for as long as you want the random number to be the same. Hint: use date() to construct a number based on the date. Then call mt_rand to get a random number. You can tell it to return a number within a range. -
It's not about dependency. It's about inheritance. Extending a class is saying "this class here is a specialized type of this other class". An action is not a specialized form of a view. An action may use a view, but it shouldn't be inheriting from it.
-
What property? I don't see it mentioned anywhere else in this thread.
-
Naming consistency? Hardly. That's a job for coding standards and IDEs that can automatically (re)format code for you. Rather than rehash something that is a fairly complicated subject, let me point you to, honestly, the first four results I found in Google that looked decent: - Why you should always use PHP interfaces - Understanding and Applying Polymorphism in PHP - Design Pattern Principles for PHP: Program to an Interface; not an implementation - When should I use an interface/abstract class?
-
If you say that because you got object notation {...} then that doesn't matter much: objects and arrays in Javascript are very nearly interchangeable. (That's why I said "array" with quotation marks.) How does it "not work"? Or put another way, what output are you getting and what are you trying to get? Because like Jacques1 said json_encode() is what you should be using, so any problems you're having will about how you're constructing the PHP array or using the Javascript array.
-
Does this regex need the backslash before the dot? ^\S+@\S+\.\S+$
requinix replied to appobs's topic in Regex Help
Email addresses suck, as you've seen. Go only for the rudimentary structure, prompt twice to try to catch typos, and send a message to really confirm it. The only other thing you can do beforehand is to look up the domain name and make sure it exists, but everything imaginable does now so you won't catch much. A strict check will only piss off the people with unusual but legitimate addresses. You know, the 0.001% who do it just so they can bitch about how validation forms don't accept it. The other people will just enter in a made up email like "foo@bar.com" and no regex can possibly catch that. "The regular expression does not cope with comments in email addresses"... Mine does -
I assume you mean var array_one_results = new Array(); array_one[1][0] = 40; array_one[1][1] = 50; array_one[2][0] = 40; array_one[2][1] = 50; As long as you can get your PHP array to look exactly like the Javascript "array" you want, var array_name = <?=json_encode($array)?>;That's all it takes.
-
Unless you're actually trying to set static properties, it should be $this->$attribute_name = new $model_class();
-
Does this regex need the backslash before the dot? ^\S+@\S+\.\S+$
requinix replied to appobs's topic in Regex Help
Probably not the one, but I love showing this off any time I get the chance. /^(((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P\(((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(([\x21-\x27\x2A-\x5B\x5D-\x7E]|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F])|(\\([\x21-\x7E]|[\x20\t])|\\(\0|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|\n|\r))|(?P>COMMENT)))*(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?\)))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+(\.(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+)*((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?\x22((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(([\x21\x23-\x5B\x5D-\x7E]|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F])|(\\([\x21-\x7E]|[\x20\t])|\\(\0|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|\n|\r))))*(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?\x22((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|(((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?\x22((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(([\x21\x23-\x5B\x5D-\x7E]|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F])|(\\([\x21-\x7E]|[\x20\t])|\\(\0|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|\n|\r))))*(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?\x22((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?)(\.(((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?\x22((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(([\x21\x23-\x5B\x5D-\x7E]|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F])|(\\([\x21-\x7E]|[\x20\t])|\\(\0|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|\n|\r))))*(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?\x22((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?))*)@(((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+(\.(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+)*((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?\[((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?([\x21-\x5A\x5E-\x7E]|([\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|(\\([\x21-\x7E]|[\x20\t])|\\(\0|[\x01-\x08\x0B\x0C\x0E-\x1F\x7F]|\n|\r)))))*(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?\]((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?|((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(\.((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?(([A-Za-z]|[0-9]|[!#$%&'*+\-\/=?^_`{|}~]))+((((((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?(?P>COMMENT))+(((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*))?|((([\x20\t])*\r\n)?([\x20\t])+|([\x20\t])+(\r\n([\x20\t])+)*)))?)*)$/Programmatically generated so it can be cleaned up a bit, but still... -
Does this regex need the backslash before the dot? ^\S+@\S+\.\S+$
requinix replied to appobs's topic in Regex Help
If it has the backslash then it means a literal period. If it does not then it means any character. So what would you think? Are you making sure to test with valid and invalid strings? You did see that it's called "a Ruby regular expression editor", right? There are many other options that specifically say they're good for PHP and/or PCRE (which is what PHP uses). Ruby's regex syntax looks the same but I wouldn't rely on that. -
Something I've used many times is an include function. function include_clean(/* $file, array $args */) { if (func_num_args() > 1) { extract(func_get_arg(1)); } return include func_get_arg(0); } include_clean("a.php"); include_clean("b.php", array("bee" => $bee));
-
Yeah. It may not be what you were originally thinking but it is the best solution. Remember that databases are specifically designed to deal with many rows of data. Shift those rows into columns and you lose one of the huge advantages of a relational database.
-
Auto mode should be fine.
-
Should I let users add comments without logging in?
requinix replied to man5's topic in PHP Coding Help
Unsolicited advice: Don't allow businesses to delete comments. Otherwise they'll delete the ones they don't like and your site will get a bad reputation for it. Let people and businesses report comments for spam or bad language or whatever, then have trusted users (moderators) decide. -
Should I let users add comments without logging in?
requinix replied to man5's topic in PHP Coding Help
They have to give a name and email. You don't know if it's actually theirs, nor if it's even real. Not requiring a log in means allowing anonymous comments. Do you want anonymous comments? -
I would recommend what bsmither said (which is only a little bit more than davidannis said). I have actually used that pattern myself for a site where I needed to store multiple translations of various strings. You definitely shouldn't be using multiple columns. As a rule of thumb, adding more of something you already have, such as more languages, should not require modifying database structures.
-
The ".png" is alright, though you really should rename it. Downloaded, it looks like a PNG to me, which suggests it really is corrupted. Did you upload the file using binary mode? (Or how did you upload it?)
-
ereg and preg are for regular expressions - things much more complicated than simple strings like "\r". Use str_replace instead.
-
How to take automatic preview of apk file using php?
requinix replied to Palashfog's topic in PHP Coding Help
Your post is missing the part where you explain what you're talking about. -
"Object"? So you've already decoded the JSON? Well, your code is the one making the decision about which method to call, right? So... your code knows what format the data will come back in. So... the code that calls getSummoner() knows it only has the name to work with, and the code that calls getSummonerByName() knows it has additional information. So... I guess I don't see where the problem is?
-
$data = json_encode(array($rows2));Or construct $rows2 differently, like $rows2 = array(); // add stuff with $rows2[] = ... $data = json_encode($rows2);
-
No experience at all. It's just that reading code is easier than writing it. You may be able to get away with putting the . In general the placement shouldn't matter.
-
You're executing a query to get those numbers, right? What's the query? I bet we could change it a bit to return exactly the results you want.
-
So I found the player and had it decompiled. The part where it deals with the config XML looks like if (_root.xml != undefined) { _xml.load(_root.xml); } else { _xml.load("config.xml"); } _xml.onload = function (success) { var _local3 = 0; while (_local3 < this.firstchild.childnodes.length) { if (this.firstchild.childnodes[_local3].nodetype == 1) { if (this.firstchild.childnodes[_local3].nodename != "play_list") { o[this.firstchild.childnodes[_local3].nodename] = this.firstchild.childnodes[_local3].firstchild.nodevalue; } else { o[this.firstchild.childnodes[_local3].nodename] = new array(); var _local4 = 0; while (_local4 < this.firstchild.childnodes[_local3].childnodes.length) { if (this.firstchild.childnodes[_local3].childnodes[_local4].nodetype == 1) { o[this.firstchild.childnodes[_local3].nodename].push(this.firstchild.childnodes[_local3].childnodes[_local4].firstchild.nodevalue); } _local4++; } } } _local3++; }The part where it deals with "this.firstchild" is where it fails: by inserting the processing block, the first child is no longer the and the code starts to fall apart. tl;dr: the player reads the XML poorly.