-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
IMO the "guideline" is the marks/comments so that you will improve next time around. Remember, school is a learning process, where you go from suck to not suck. It's not intended to be perfection every round. Also, it is a good thing to an extent to defend your work, but in the real world...you're always going to have a boss who tells you one thing and means another, and "That's not what you said" only goes so far. So, you should take this as a lesson to take it upon yourself to ask questions and get clarification on everything beforehand. Remember, the reason you (will) have the job is because you know the details, not the boss - they don't know any better, so it is up to you to pry that shit out of them. But anyways, yeah I agree as far as commenting. Always err on the side of over-commenting. If it's your own code that only you will ever touch, and you're confident in yourself that your naming conventions are enough for you, that's fine. But in the real world where you're working with lots of other peoples' code and they yours, there's really no such thing as too many comments. Also want to mention that when you comment, you need to comment what your intentions are, what you are expecting to happen. The code reflects the comments, not the other way around. IOW the comments are there to explain in human language what the script is supposed to be doing. For me, my pseudo-code usually turns into my comments. But also, comments are especially important if you're trying to track down a logic bug. The first and most important step to tracking down bugs is to figure out what it's supposed to be doing in the first place, so if you have clearly written comments then you can compare them to the actual code and more easily find those bugs. "Oh hey, it says here that I'm supposed to be doing xyz but the code clearly doesn't do that!" sort of thing.
-
Okay so here is a tl;dr.... First off, a couple things to understand: To clarify preg_match() return values: With no 3rd argument, preg_match() returns integer value of 1, 0 or boolean value of false. "false" only happens if it returns an error from parsing (like you forgot a delimiter or something) so for these examples, the "false" output is never because of this, because the syntax is correct. IOW in these examples, preg_match() itself always returns an integer value of 1 or 0. 2nd point is that ! is the logical NOT operator. It returns a boolean false if the expression evaluates true, and a boolean true if the expression evaluates false. 1 evaluates true and 0 evaluates false. So for instance, if preg_match were to return an integer of 1 because it matched something but you have a ! in front of it, 1 is true so the ! will return a boolean false. 3rd point is that two of these are "right", if you put your "give error" code vs. "perform query" code in the right place based on the logic. But one of them is more clear, based on how people read things in general, or how the rest of your code is setup. So even though there are multiple "right answers" per se, you should pick the version that clearly conveys your intentions and makes the code easiest to read. Also, there are two wrong answers here, which are demonstrated in the code examples below. 4th point is that when I refer to "valid" or "invalid" string (the posted username), there are 2 different contexts: 1) what YOU intend to be valid (a username with only letters or numbers, 5 to 20 chars long), and 2) what the regex pattern considers an (in)valid match. Hopefully you can see from the context what I mean, and I also try to be explicit for the most part. This is important to understand, so that you can understand why the two wrong answers are wrong. So.... based on those things, let's look at the examples 1) positive char class with logical NOT operator The regex matches for 5 to 20 numbers or letters, and the NOT operator inverts the result var_dump(!preg_match('/^[A-Za-z0-9]{5,20}$/','12345')); // output: bool (false) var_dump(!preg_match('/^[A-Za-z0-9]{5,20}$/','123')); // output: bool (true) var_dump(!preg_match('/^[A-Za-z0-9]{5,20}$/','.....')); // output: bool (true) '12345' is valid to you AND to the regex (right chars, right length). preg_match() returns an integer value of 1, which evaluates true, but the ! operator inverts that and returns a boolean false. '123' is invalid to the regex AND to you (right chars, wrong length). preg_match() returns an integer value of 0, which evaluates false, but the ! operator inverts that and returns a boolean true. '.....' is invalid to the regex AND to you (wrong chars, right length). preg_match() returns an integer value of 0, which evaluates false, but the ! operator inverts that and returns a boolean true. The following codeblock will technically work, but it is not very clear, because it's evaluating "true" on what you consider to be invalid usernames : if ( !preg_match('/^[A-Za-z0-9]{5,20}$/',$_POST['Username']) ) { // will execute if username '123' // will execute if username '.....' } else { // will execute if username '12345' } 2) negative char class with logical NOT operator The regex matches for 5 to 20 of anything NOT a number or letter, and the NOT operator inverts the result. var_dump(!preg_match('/^[^A-Za-z0-9]{5,20}$/','12345')); // output: bool (true) var_dump(!preg_match('/^[^A-Za-z0-9]{5,20}$/','123')); // output: bool (true) var_dump(!preg_match('/^[^A-Za-z0-9]{5,20}$/','.....')); // output: bool (false) '12345' is valid to you (right chars, right length) but invalid to the regex (wrong chars, right length). preg_match() returns an integer value of 0, which evaluates false, but the ! operator inverts that and returns a boolean true. '123' is invalid to you (right chars, wrong length) and invalid to the regex (wrong chars, wrong length). preg_match() returns an integer value of 0, which evaluates false, but the ! operator inverts that and returns a boolean true. '.....' is invalid to you (wrong chars, right length) but valid to the regex (right chars, right length). preg_match() returns an integer value of 1, which evaluates true, but the ! operator inverts that and returns a boolean false. This will not work in an if..else because your expectations and the regex's expectations do not line up 100%, so you will end up with false positives! // bad! if ( !preg_match('/^[^A-Za-z0-9]{5,20}$/',$_POST['Username']) ) { // will execute if username is '12345' // will execute if username is '123' } else { // will execute if username is '.....' } 3) Positive char class without logical NOT operator The regex matches for 5 to 20 numbers or letters var_dump(preg_match('/^[A-Za-z0-9]{5,20}$/','12345')); // output: int (1) var_dump(preg_match('/^[A-Za-z0-9]{5,20}$/','123')); // output: int (0) var_dump(preg_match('/^[A-Za-z0-9]{5,20}$/','.....')); // output: int (0) '12345' is valid to you and the regex (right chars, right length). preg_match() returns an integer value of 1, which evaluates true '123' is invalid to you and the regex (right chars, wrong length). preg_match() returns an integer value of 0, which evaluates false '.....' is invalid you and the regex (wrong chars, right length). preg_match() returns an integer value of 0, which evaluates false The following codeblock will work, and the intention is clear: "if the username is valid, do this..otherwise do this" if ( preg_match('/^[A-Za-z0-9]{5,20}$/',$_POST['Username']) ) { // will execute if username '12345' } else { // will execute if username '123' // will execute if username '.....' } 4) negative char class without logical NOT operator The regex matches for 5 to 20 of anything NOT a number or letter var_dump(preg_match('/^[^A-Za-z0-9]{5,20}$/','12345')); // output: int (0) var_dump(preg_match('/^[^A-Za-z0-9]{5,20}$/','123')); // output: int (0) var_dump(preg_match('/^[^A-Za-z0-9]{5,20}$/','.....')); // output: int (1) '12345' is valid to you (right chars, right length) but invalid for the regex (wrong chars, right length). preg_match() returns an integer value of 0, which evaluates false '123' is invalid to you (right chars, wrong length) and invalid for the regex (wrong chars, wrong length). preg_match() returns an integer value of 0, which evaluates false '.....' is invalid you (wrong chars, wrong length) but valid for the regex (right chars, right length). preg_match() returns an integer value of 1, which evaluates true This will not work in an if..else because your expectations and the regex's expectations do not line up 100%, so you will end up with false negatives! // bad! if ( preg_match('/^[^A-Za-z0-9]{5,20}$/',$_POST['Username']) ) { // will execute if username is '.....' } else { // will execute if username is '12345' // will execute if username is '123' }
-
Just out of curiosity... Facebook.
.josh replied to phpfreak's topic in PHPFreaks.com Website Feedback
If only he said sudo make me a sammich... -
if (!preg_match('/^[^A-Za-z0-9]{5,20}$/',$_POST['Username']) ! This means the inverse of what is returned from preg_match(). preg_match() without a 3rd argument will return true if a match occurred, false if no match. So putting the ! in front of it inverses that for the "if(...)" condition. So if preg_match() returns true (match occurred), and you have ! in front of preg_match, the expression inverts that to false, so the condition evaluates false. ^ outside of the [...] this signifies start of string anchor tag (or start of line if you use a modifier, but that's another can of worms). This is, coupled with the $ (end of string/line counterpart) ensures that the match is being performed on the whole string, not just a substring within the string. ^ The [...] brackets is called a character class. It's basically a list of characters to match for. Having a ^ at the start [^...] means to match anything NOT within the [...] brackets (which makes it a negative character class).
-
http://www.thinkgeek.com/geek-kids/newborn-infant/ http://www.jinx.com/shop/g/baby/
-
Just out of curiosity... Facebook.
.josh replied to phpfreak's topic in PHPFreaks.com Website Feedback
I tend to agree. I see the same types of questions/problems/people at my job as I do here, so it's no stretch of the imagination to assume that some % of our population is more than random hobbyists. Also, why else would we constantly get "please delete my thread/account, I don't want my boss/client to ever find this" threads? -
Just wanna throw out there that if you're simply looking to see if $_POST['name'] only has letters or numbers and you there is no length limit etc.. you don't even need to use regex, just use ctype_alnum if (ctype_alnum($_POST['name'])) { // it's good, do something } else { // it's bad, do something }
-
Also you're probably going to run into trouble with those greedy quantifiers...
-
As someone who writes technical manuals and docs for a living, I advise you to take the time to read it, even if it's a lengthy read. For sure, not all 1k pages are relevant to this situation, but I'm positive they are all relevant to a situation. No doubt one of the best ways to improve yourself as a programmer is to RTFM
-
lol that would be cool, I haven't gotten to try minecraft yet
-
In general you shouldn't be aiming to simply have different translations of your pages, but aim to have localized versions of the pages. But even still, it will not hurt you to have separate URLs for each translation, because the search engine algorithms will not really put them in the same bucket at a higher level. When you do a search for "apple" do you see results popping up in spanish? Same principle. You will have your english version page competing against other english key-word pages, and your spanish version competing against spanish keywords, etc... and Adam makes a good suggestion for how to structure your URLs for it. But while we're on the subject of SEO...you should work on making your URLs more friendly than ".../posts/21". I'm gonna assume that you have some sort of CMS like WordPress and those are blog/article posts... most CMSs have built-in the ability to set the URLs to be more SEO friendly than having an ID like that. Basically they will take the title of the blog/article and use that, or some other value you specify, so that you get something more like "mysite.com/top-10-things-you-never-knew.html" or something. This is 100x better than having an ID in the URL that means nothing to crawlers. And if your site doesn't have something like that built-in, then you really need to invest in doing it. Here is a link to some SEO best-practices, straight from the horse's mouth: http://static.googleusercontent.com/external_content/untrusted_dlcp/www.google.com/en/us/webmasters/docs/search-engine-optimization-starter-guide.pdf
-
I assume this is in regards to your Almost there... thread. From that thread, this is what I see: You made a post asking for help (but did a poor job asking the question, see my response in your thread). We have forum stickies for a reason. Contrary to the belief of some people, they are not there so that we can be assholes on power trips. They are there because we know from a lot of experience trying to help people that we need certain info in order to help with a problem, and that usually when a person asks for help, they rarely know how to even ask for that help. You PMed Xyph asking for help, which is against the rules. You defended your PM to Xyph by saying it is frustrating when nobody bothers to reply when you've had this problem for a week+ straight. First off, less than 24 hours passed between your OP and Xyph's response, so you PMed him sometime in between. Whether or not you've had this problem for a week+ we don't know; as far as we're concerned, your problem started when you made the thread, so you waited less than 24 hours before you PMed Xyph, not a week+ (not that it would make it any more okay to PM someone even if it were a week+). Whether or not you choose to read the rules is on you, but they are enforced just the same, and not knowing them is not an excuse. We have them clearly posted and even have explicitly added a notice and link in red, right above every Post/Preview button on the board. You also responded by asking a basic question that could have easily been googled. Yes, you have a "right" to ask questions (insofar as that our terms give you this right...this is a privately owned site), but if you're relying on a free service to ask questions, it is common knowledge that free services do not cater to questions that can easily be found on your own. Relevant results appear on the first page of google even with just the term "quantifier", not even throwing in other keywords like "regex" "php" "programming" etc... ...and should you decide that we're a bunch of elitists for having this mentality, I invite you to spend a week+ in our shoes before making that judgment. Offer your own expertise(s) for free and see how long it takes you to start trying to filter out stuff. Use some common sense. It's like finding a magic lamp and then wishing for something stupid and common and easily obtainable that you totally didn't need to burn a wish for. But even still, we're not the internets' personal genie at beck and call, required to grant whatever comes out of peoples' mouth fappings. In summary, I see that you didn't bother to read the rules and consequently broke them, and didn't bother to read stickies and consequently asked your question poorly. And then you get all pissy because nobody bothered to respond, and when they did, they called you out on it. So after 2 years of expecting us to cater to your lazy rude ass, you have decided that we fail and are moving on. Well I'm *so* sorry to disappoint. You walked into our house and didn't bother to take your muddy shoes off, plopped yourself down on our couch and propped your feet up on our coffee table and started yelling at us to make you a sammich....fuck off.
-
We have stickies for a reason. Contrary to the belief of some people, they are not there so that we can be assholes on power trips. They are there because we know from a lot of experience trying to help people that we need certain info in order to help with a problem, and that usually when a person asks for help, they rarely know how to even ask for that help. It's kind of hard to know what the problem really is when you didn't properly explain the problem in the first place. You show your regex, which is good. But then you point at two of the array entries and show a picture of a list. You did not explain what the problem actually is. My best guess is that you're saying the bullet points aren't lined up properly but it's only a guess. You failed to show the subject, the content you are trying to perform the regex on. Nor did you show what the preg_replaces are doing vs. what you want it do. Also, if the issue is that the bullets aren't lined up properly, it's probably not even a regex issue, but a styling issue (css).
-
You can work yourself up to at least Guru membergroup status and be able to post tutorials yourself. Or you can submit to can submit the tutorial to us for review.
-
This thread is not meant to promote using frameworks instead of using core javascript for everything. That is just silly. Frameworks are not alternative languages, they are tools built on existing languages to make certain things easier. This thread is about using a framework for AJAX specifically.
-
What this board is for If you have some code you are wanting people to debug, or a website you are working on that you want people to 'beta test,' post the code/link here. The idea of this forum is that you have finished your code, and now you wish for people to test it for weak spots, logic problems, etc.. While you can of course expect feedback from your testers, if you need more help fixing your code, use the Help forums. This forum is for testing and testing feedback ONLY. This is NOT a "rate my script/site" forum. Please go to the critique forum for that. Try to give a good description of what your code is supposed to be doing. We can do little more than find syntax errors if we don't know what it's supposed to be doing. Your topic doesn't show? All new topics are moderated, meaning that they will not show up until a staff member approves it. Read the rules for posting in this forum and follow the directions. Some advice to be cautious Be very careful on what kind of info you post, especially when it comes to posting links to your site. Posts of this nature are often times aliases of "please try to hack my site and tell me if you do, and how, so I can fix it." We cannot and will not be held liable for any kind of damage or loss that results from you posting any of your stuff here (or anywhere else on the site, for that matter). Not everybody out there is honest. Someone out there may read your post, go to your script, find a security hole and exploit it without telling you, all the while giving you the thumbs up. Rules Regarding "Exploit Scanners" Use of exploit scanners can be an effective way to discover exploits on a website, so we have no intention of banning posting scanner results. But these scanners can also return bogus results. Secondly: Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. As of now, posting scanner results is only allowed under the following conditions: 1) You must share the name and how to get the scanner 2) You absolutely MUST explain every item in the result (why is this a risk, not just because the scanner says so) As with all forum rules, ignoring these could lead to moderation action. Ignorance of these rules is not a defense. Thank you for your cooperation.
-
...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it). Or...someone is trying to build their own framework. That's it! IMO there has been no other reason worthy enough to warrant not using jQuery or the like! "It will bloat my website, increase page load time, blahblah" is not a good enough reason! These frameworks are compacted and browsers will cache them! So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?" Seriously. It is super easy. Way easier than that code you're trying to post. Save yourself the headache. Get jQuery or similar. DO IT.
-
Also, since we probably won't be jumping in individually welcoming every single person comes by, here's your generic welcome message: Greetings, ___________ ! Thank you for joining the board! Feel free to ask any question, but please don't be stupid about it. Make an effort to pick the right forum, make an effort to be detailed about your question, make an effort to read relevant stickies/rules, and we'll make an effort to help you. .CV
-
http://www.phpfreaks.com/tutorial/php-basic-database-handling
-
"level system" is pretty ambiguous... care to be more specific?
-
http://www.phpfreaks.com/tutorial/php-add-text-to-image
-
GENERAL RULES AND GUIDELINES FOR POSTING This forum is not meant to be a formal freelance service system. It is available for those who wish to seek out services or work from other people, as a courtesy to the members of the phpfreaks community. phpfreaks.com does not specialize in freelance services. This forum is an informal mechanism, as a courtesy to the community. We have no formal mechanism in place (like escrow) to guarantee payment, refund, work done, etc... phpfreaks.com shall not be held responsible for any losses you incur. we have never and continue to not act as any kind of mediator or verification/compensation source for people/organizations who use those forums. We will not be held responsible/liable for any damages, loss, etc. that occur from use of those forums. If you hire someone and they rip you off, don't come crying to us. If someone hires you and they rip you off, don't come crying to us. Those forums are a convenience. If you want something more official that offers guarantees, go to a real freelance site! If you have any questions regarding the freelance forum, feel free to ask them here. RULES: WHERE TO POST:If you want to offer your services, post in the Service Offerings sub-forum.If you want to offer a job or position of employment, post in the Job Offerings sub-forum. DO NOT post your 'resume' in job posting threads. You must directly contact the person you wish to reply to. The only reason replies are allowed is to ask for clarification/details about the job. Failure to adhere to this rule will result in all kinds of things, like you getting banned, or us disallowing replies. DO NOT make more than one thread offering your services. You can edit/reply to your thread to reflect additions/changes. DO NOT post advertisements to other sites offering freelance system services. For example, rentacoder.com, odesk.com, etc.. we have no partiality for or against those sites, but posts such as those are regarded as advertisement, which is against our main site rules. We fully acknowledge that this freelance system is limited, but we aren't here to provide free advertising for other places. If you prefer to do actual business through one of those sites, please specify in direct contacts with the person. You are allowed, as a freelancer or freelance company, to post a link to your personal portfolio/company to those sites, or a site that you own. But general promotions to those other sites are not allowed. GUIDELINES: When posting in the freelancing forum it's important that you provide a way for users to contact you. They will not be able to reply to your topics so they need a way to contact you privately. This can be using PMs, emails, any type of instant messaging service (MSN, Gtalk, AIM, Jabber, etc.) or however you see fit.The more specific you are about your skills, previous experience(s), availability, rates, etc.. the better your chances of getting serious inquiries. Posting vague "I'm available for anything and everything" might get more inquiries on average, but there's a good chance that it will come to nothing, based on any number of things that you could have posted here in the first place. Better to receive 10 emails from people who have some idea of your qualifications/terms, than 100 emails that don't.Be honest about your skills. All day long we see people posting about how they jumped on a job and bit off more than they could chew. They tell the client they can do everything they need and more, promise them the moon, and then promptly crap their pants about 5 minutes into it. Don't be that person! Some people get lucky and figure it out. Some people get lucky and get help that figures it out. Most people end up having to give up the project. Which leads us to....Wasting people's time and money. You waste the client's time. You waste your own time. That bad rep will more than likely come back to haunt you. All day long we get people trying to get us to delete their posts because they don't want their skeletons to come out of the closet (no we won't hide them for you). So be smart! Do the simplest easiest thing to avoid all this headache: be truthful about your skills. If you feel that being truthful will limit your potential clients, then get off your bum and hit the books. You can't seriously be in the business of trying to con people, are you?Be very clear about what you are doing. Some clients know your job, and are just looking for extra set of hands. Most do not, and therefore seek someone who does. Therefore, if you want to avoid headaches, it is your responsibility to be very clear about what it is you're going to do. What you're willing to do. What kind of support you offer after the fact, etc... on that note..Be up front and thorough about your prices. Take a look at the situation. Quote a price for it. Quote prices for things that might come up later. The more you have to go back later saying that xyz was unforseen or xyz wasn't part of the deal, regardless of whether or not you are in the right, the more you are going to come off as shady, to the client. It's like when you take your car to a mechanic and that funny noise goes from being one little $50 thing to a $2000 rebuild because the mechanic kept coming back to you saying something else is wrong. That stuff may indeed be needed, but the fact that you didn't think about it and let them know ahead of time speaks volumes about your skills as a coder. Some things just aren't foreseeable. Most things are.
-
I believe thorpe is working on something like that right now. Don't have an ETA or anything.
-
How about a captcha tutorial? Lots of them around, but we're supposed to be a resource, right? I may do it myself, if someone else doesn't volunteer.
-
Honestly I don't really see anybody writing a tutorial like that on a technical level (actual code). Maybe on some kind of abstract level, like conveying general principles and program flow and good design, advice and pitfalls, etc.. but most tutorials that involve actual code are for teaching how to make building blocks. Things like forums and blogs and cms' are more like actual buildings, not building blocks. If you sit down and break down for instance all the things in a forum, you will quite easily find tutorials for just about all of those 'building blocks.' I suggest you either do that, or maybe find an open source version of one of those things and jump into it, instead.