Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. to clarify and expand on ChristianF's post... edit: good lord i went off on a tangent, made a tl;dr..but in case you are interested in lots of details... Square brackets signify a character class. It will match any one thing listed there, and the + after that quantifies the character class, meaning to match one or more of any one thing listed in the character class. So IOW, it will match any combination of characters listed in the bracket, any length, minimum 1 char. The most immediate reason why it "worked" with php but not js is because this: '/[\.html]+$/' php expects a pattern delimiter as part of the pattern (you use the forward slash / as the delimiter). So in php, that doesn't actually count as part of the pattern. So with php, it was matching because it did find your string end with an "l" (but not necessarily the full ".html" because a character class matches any one character in it, and the + asks for one or more of that, so it will also match for instance your string ending in "htttmmlll"). So it coincidentally matched your string ending in .html because the "l" happened to be the last character, not because it explicitly ended in a full ".html". sidenote: you don't need to escape the dot when it is inside a character class; it will be treated as a literal dot (but you do need to escape it outside of a character class). So what you really should be doing in the php version is this: preg_match('/\.html$/',$string) But on the other hand in javascript, the argument passed to RegExp() does not use a pattern delimiter, so when you do this: var pattern = new RegExp('/[\.html]+$/') The regex is going to expect those forward slashes as part of the actual pattern. And the character class thing still applies. So for instance, "randomstring/l/" would match true, because [\.html]+ only requires any one of those chars, and it is surrounded by literal forward slashes. "sompage.html" would match false, because even there are no literal forwardslashes in that string "sompage/.html/" would match true by coincidence because the character class pattern and quantifier will coincidentally match ".html" and it is surrounded by forwardslashes "somepage/.hhlllmmm...ttt/" would match true because again, the character class will match any of those characters and the quantifier allows it to repeat one or more times, and it is surrounded by literal forward slashes So in javascript, in order to match for a full, literal ".html" ending, you would use this: var pattern = new RegExp('\.html$'); var result = pattern.test(str); The dot is escaped because it has special meaning in regex and you are wanting to match for a literal dot. As ChristianF pointed out though, you don't actually need to create a regex object for this, you can do it like this: var result = str.match (/\.html$/); In this example, the forward slashes are used. In javascript, a string wrapped in forward slashes instead of quotes signifies a regex object literal. This is a "shortcut" if the pattern is static (will be a hardcoded string). If you need to include a dynamic value in the pattern then you will have to create a regex object with the RegExp() instead. For example: function stringEndsWith(haystack, needle) { var pattern = new RegExp(needle+"$"); return haystack.test(pattern); } This function will allow you to do for instance stringEndsWith("somefile.html","html"), because you can use variables in the pattern passed to RegExp(). Sidenote: this function is simplified for demo purposes. In reality, this function would be more complex, because you will want to escape characters in needle that have special meaning in regex, and it's kind of a headache because you also have to escape the escape character so it isn't interpreted literally. But there's no way to use a variable in a regex literal. You can't do .match(/needle+"$"/) because it will interpret it as the literal string needle+"$" to be matched. So for instance your string would have to literally be a value of like var string = 'some string needle+"$"'; Nor can you do .match(needle+"$"), because it will parse needle but append a literal $ to it instead of match it as the end of string. So for instance, var haystack = "this is a foobar$ more stuff foobar"; var needle="foobar"; return haystack.match(needle+"$"); This will match that "foobar$" because it looks for a literal substring of "foobar$". It will not match the "foobar" at the end of haystack because $ is interpreted literally instead of as a marker for end of string, and that "foobar" at the end of the string does not end with a literal $. Also sidenote even if you add it to the end, it still wouldn't match because .match will only look for and match the first occurrence of "foobar$" unless you add the global modifier (g)..which you can't do in this example because the modifier can only be added if you used the regex literal version or passed a RegExp object, and this version is just a string being passed to .match(). IOW you can't do .match(/needle+"$"/g) to do a global match because then you're back to the first "can't do" example where needle+"$" is treated as a literal string instead of looking for "foobar$". The overall point is that there are a lot of limitations with using a regex object literal, so if you're looking for a simple, static string match, then it's a nice shortcut. But if you're looking to be able to expand or make it dynamic (now or in the future), stick with making a RegExp object.
  2. we do. We're not here to help people rip other people off.
  3. I found this link https://bugs.php.net/bug.php?id=32100 near as I can figure most "pro" finally people basically say this is unnecessarily duping code: try { // allocate resources } catch (e) { // deallocate resources } // deallocate resources and finally will fix that by doing: try { // allocate resources } catch (e) { // anything else, but catch not even needed } finally { // deallocate resources } What I don't understand is, why can't you just do this? try { // allocate resources } catch (e) { // anything else, but catch not even needed } // deallocate resources
  4. You can clean up your own mess as you go (for instance close db connections), but php does clean up all of that when the script ends. But even still, this isn't a "run this before the script ends" thing unless you wrap the entire script in a giant try..catch..finally - something I doubt most people would actually do... I'm sure I'm missing something here..I can't see how something so useless/pointless would make it into php ... but.. I just can't think of a good use case, so.../shrug
  5. okay well, fair enough, you *can* do that...but why? Wouldn't it be more prudent to not have that die (or return etc..) in there? Still not gettin' it :/
  6. @xyph: but why can't I just do try { $template->output('header'); $data_sidebar = $control->getStuff($userData); $data_content = $contro->getOther($moreData); $template->buffer('sidebar',$data_sidebar); $template->buffer('content',$data_content); $template->flush(); } catch ( Exception $e ) { $template->clear_buffer(); $template->output('error',$e->getMessage()); } $template->output('footer'); I'm not seeing what the advantage of using finally is, over this?
  7. or i guess more accurately... just do whatever i'm going to do after the try...catch, not inside it. how is doing it within 'finally' different?
  8. okay i readily admit i'm not the brightest crayon in the box...can someone please explain why this is cool or useful? Why wouldn't i just put whatever would go in the 'finally', into the catch instead?
  9. onchange gets called after focus of the input field is lost (you focus on another form field or click on another part of the site, etc..). You need to call your function in the onkeydown, onkeypress or onkeyup attrib instead
  10. you can use file_get_contents or the cURL library to retrieve the contents of a page. Then you would use a DOM parser or regex functions (like preg_match_all) to scrape the values off the page. WARNING: You should always get permission from the site owner before scraping their content. People do not take kindly to others scraping their content and doing so has adverse effects. You may have your IP blocked or you could get sued, depending on lots of factors. I know there are a lot of sites that offer ability to grab current currency rates through a feed or an api. You will more than likely have to pay for such service, depending on how current you want the information to be, though.
  11. given that sandy1028 has a post history here being the coder, my mind went the other way, thinking that (s)he flubbed their resume and wants to hopefully bluff.
  12. You are a new guy walking in to fix "problems." That's going to involve a lot of stepping on toes, because most everybody there will have either been directly or indirectly a part of those problems being there in the first place. Experience will teach you that even good coders are sometimes more often than not forced to do bad things because of red tape and politics vs. deadlines. Does it suck? Yes. But that's the reality of things. And nobody likes being told their shit stinks, even if it is because they really do suck, but especially if it's not their fault. But you don't know the history behind any of that stuff, because you are new. In my experience, the best way to go about it is to assume everybody there is decent, and that any "baddie" thing you see, is because of something someone was forced to do as a lesser of the evils or most feasible option at the time. Just try to be really tactful about things. "Hey, I think we can improve this by.." vs. "Omg this is crap, wtf was someone thinking?" because you never know if the person you are talking to was directly or indirectly involved in the coding or decision behind what you are talking about. And it doesn't matter if it boils down to someone being terrible at their job and not because of circumstance. Your job will always become harder when people are on the defense, so try really hard to choose how you say it in a way that won't put someone on the defense.
  13. @kicken: lol I remember playing #2 w/ paper/pen when I was a kid, sittin' in church w/ my siblings
  14. I'm a big fan of "generator" type scripts, especially ones that have to do with words. Example: IT Department [name] Generator from seventh sanctum
  15. 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.
  16. 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.
  17. 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.
  18. ...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.
  19. 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
  20. http://www.phpfreaks.com/tutorial/php-basic-database-handling
  21. "level system" is pretty ambiguous... care to be more specific?
  22. http://www.phpfreaks.com/tutorial/php-add-text-to-image
  23. 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.
  24. I believe thorpe is working on something like that right now. Don't have an ETA or anything.
  25. 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.
×
×
  • 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.