-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
And there is also the country code (1) to consider. In the US, you usually do have to include the country code in order to call a number in the US that is outside of your area code - or even calling someone in your area code but you want to specify the area code for some reason. For example, if I want to call my friend Texas and I'm up in New York (different area code), I would have to dial a full 1-555-444-4444
-
Hello All, Most of us on the staff like the idea of hosting contests here. In the past, we've tried to do it, but our attempts were fail. We have more or less been in agreement that the reason the contests failed was due to lack of prizes that anybody really cared about. Well we've been talking about it and we think we have enough people willing to chip in towards handing out some decent prizes. Nothing substantial like thousands of dollars...but enough to hand out something smallish but cool like books or $20 amazon or thinkgeek giftcards etc... So first off, we'd like to see how many people would even be interested in competitions around here. So cast your vote in the poll! But second, we'd also like to hear from people about contest ideas and suggestions, so please post your contest suggestions in this thread. To give an idea of scope, back in the day, we tried out two contests: one was to make a graphing calculator and the other one was to make a text based fighting game. IMO both were pretty cool ideas, something that has room to have cool bells and whistles but not take months on end to make, etc... so let's hear it! One last note: If you are interested in donating to the "prize" pool, please PM me! Your generosity may be rewarded with things such as joining the Supporter Membergroup (Supporters get a badge under their name to distinguish themselves from regular members, and they also have the site ads removed), or other benefits such as being a judge in the contests, etc... .josh
-
Beer tastes like carbonated piss. Just sayin'.
-
How did you make fire? Through the sheer force of will. Don't you mean...the sheer will of the force? *.josh busts out lightsaber
-
Yeah...our previous attempts were a whole lot of fail. Not a whole lot of interest in coming up w/ contest ideas/details (We did IMO come up with some good ideas, just not a whole lot of people participated in the brainstorming/hashing it out). Maybe a dozen people signed up tops, only 3-4 actually submitted something, judges didn't really wanna judge. And we actually did offer prizes, but the prizes TBH kinda sucked. If I remember correct, prizes were along the lines of something like subscription to some no-name online publication. Nothin' really substantial like "Free copy of xyz book! Personal robot! Free t-shirt!" And that probably made for a downward spiraling lack of interest for every step of the way... But we really liked the idea of having contests and we even approached the owner asking if he would be interested in ponying up real prizes, or maybe a percentage of the ad money and donations made here. But we got shot down on that count (Owner basically said that money is barely enough to keep the lights on (and sometimes isn't enough). Soo... we do have a desire to do this sort of thing, but no resources to offer prizes substantial enough to interest anybody or be worth it. Also, I do like the idea of some kind of badge/title for winners and that may be enough for a few people, but not really enough for most people....
-
my contributions to helping others
.josh replied to spiderwell's topic in PHPFreaks.com Website Feedback
Your intentions are good, but being able to help others and teach them is a learning process, same as anything else. I remember when I first started coming here, I would try to help people and...someone would ask how to do xyz and I would give them like 20 lines of code as an answer that *technically* worked, and then some seasoned member would come in and give them a one-liner ...the important thing is to not get mad when someone "1-ups" you on answers (even if they aren't particularly nice about it); instead, be humbled by it, learn from it. There are plenty of people who are badass coders but fail to teach others how to do what they do, etc.. it is a learning process, best learned by experience, same as anything else. The more you help out around here, the more you will not only learn php itself, but you will also learn how to better respond to questions. As others have mentioned, the important thing is to throw out a disclaimer when you are not sure or are stumbling with words, etc... -
If you are intentionally giving out wrong answers, that makes you a troll, purposely trying to sabotage the community. That is grounds for warning and ban.
-
My thought is that it is more simple and easier to code and read than having to fuck with keeping track of row lengths and file positions.
-
oh and another thing about point #3 is you could also (maybe) make your regex more efficient by swapping the order of the EOL chars in your alternation: $pattern = '~;.+?(\n|\r)~'; If the file is windows formatted then yeah, \r would be better first, but more often than not it will most likely just be \n so it is a safer bet to put that first.
-
Well the main issues with your solution are that : 1) Regex is powerful and sexy, but should always be avoided whenever possible, as it is almost certainly less efficient than using built-in functions. There are lots of different ways stripping everything including and after the first semicolon can be done without regex. One example is in my post above. Another example is using a combination of substr and strpos. You're welcome to do some benchmarking to see for yourself. 2) The OP asked for help with manipulating a file. Your solution gives an example string and does not address file manipulation at all. That in and of itself is missing the mark, but it becomes an even bigger issue considering the size of the file (150k rows) vs. your solution, which based on the context of your $str, is to perform a regex replace on the file as a whole. Loading 150k rows of a file into memory may or may not throw a "allowed memory reached" message, based on his php settings. Or it may or may not crash his server, depending on how shitty it is. But even if he has a badass server with ample memory and limits maxed or turned off, it is still incredibly inefficient to load 150k rows of data into memory all at once like that. First off, that just amplifies the inefficiency of regex vs. built-in functions (my first point). If you did some benchmark testing on your regex pattern vs. the built-in functions on one row, or even just the several rows you currently have in your $str example, the difference is negligible, not gonna lie. Even if it's twice as slow, we're talking microseconds here... but 150k rows? And that's not even considering whether this is a 1-time-only script or something that needs to be ran regularly. Your example code implies using something like file_get_contents to grab a 150k line file and then I *guess* write it back with file_put_contents. Regardless of stripping method, performing the operation 1 line at a time will always be more safe and efficient. 3) I will at least give you this: If the OP's situation is that somehow his only option is to work on the file as a whole (all in one variable) then for the most part, your regex is okay. You could make it more efficient by not having that first captured group since you aren't actually using $1 (IOW remove the first parens and use $1 instead of $2 in $replacement). But other than that...it's okay. But even still, if it came to having the whole file contents in a single variable, it would still probably be more efficient to first split at the EOL chars and do it one line at a time. 4) This point isn't really speaking towards your solution, but more towards mine. My solution involves reading the source file one line at a time and writing to a new file one line at a time. This is just speculation, but it might be more efficient to instead open the single source file for reading and writing (instead of just reading) and then doing the stripping directly in the file. Maybe. Would involve using a handful of other functions like fseek and ftell, strlen etc.. and I'm not entirely convinced that would really be more efficient (and it would certainly be more complex coding and readability-wise) than just writing results to a new file. But I am mentioning it in the event that writing to a new file somehow isn't an option.
-
AyKay your solution is bad on so many levels I can't even begin...just, no. Just walk away. $sourceFile = fopen("sourceFile.txt", "r"); $destFile = fopen("destFile.txt", "a"); if ($sourceFile && $destFile) { while (($line = fgets($sourceFile)) !== false) { $newLine = array_shift(explode(';',$line)) . "\n"; fwrite($destFile, $newLine); } fclose($sourceFile); fclose($destFile); }
-
you cannot do it with javascript. You can do it with an ActiveX object though. Though, most browsers and security addons have them disabled for a reason.
-
promise or threat? I can never tell the difference with you kids these days....
-
Well I'm sure most would overlook it if you were to share...
-
this won't work, because for instance, '10.44.6.' does not equal '10.44.6.1'. You use something like strpos instead. Alternatively you can use regex to match it, if you want to match ranges.
-
IMO best thing is to not allow those special chars at all.
-
strange behavior: php is escaping single quotes from flash
.josh replied to dsdsdsdsd's topic in PHP Coding Help
fyi if your host provider won't change it back, you can check the state with get_magic_quotes_gpc and use stripslashes if it is on (see example #1 of first link)...which as Pikachu pointed out, is something you should be doing anyways. -
jQuery and mootools do not natively get along with each other because by default they use the same $ namespace. I don't have much experience with mootools but I know jQuery provides an easy solution for working with other libraries (and I suspect mootools probably has an equivalent). http://docs.jquery.com/Using_jQuery_with_Other_Libraries However, the *real* answer here is really that you should pick one library or the other instead of using both. Which one is better depends on what you are ultimately trying to do, but based on the code you provided, both of them should be able to do those jobs. The benefits of using a single library are obvious: - less bandwidth consumed - faster load times, since you won't be loading 2 libraries - not having to maintain multiple frameworks - don't have to learn multiple frameworks - don't have to deal with issues like this
-
Just to clarify the above posts: $string = "jim.h|1234567890123456|1"; $regex = "~^([a-z0-9.-]+)\|([a-z0-9]{16})\|([1-3])$~i"; if ( preg_match($regex, $string, $part) ) { $sql = "INSERT INTO employees (name,key,level) VALUES ('{$part[1]}','{$part[2]}','{$part[3]}')"; } There are 2 things this regex does that was not explicitly defined: 1) you said the "name" can be any length. Well technically 0 is a length. I *assume* you don't *really* want to validate a missing name, so this regex validates on 1 or more chars. If you really don't care if a name is missing, change that "+" to a "*" in $regex. But on that note, are you sure that you *really* want to validate *any* length? What is your name column in your database set to? If it's only something like varchar(10) then it's either going to truncate or throw an error... 2) I *assumed* based on the context that it should be case-insensitive. If you really only want to accept lowercase values, remove that "i" on the end. of the $regex value.
-
Exactly. one should be happy this is happening, as it helps your SEO efforts. If you do not want this to happen... one should disallow content in robots.txt file, as most crawler bots look there and respect its rules.
-
Well for starters, you can cut out this bit about spacing. As it has already been stated, it boils down to a matter of opinion, and you even go on to acknowledge: Notice the theme here? Your spacing conventions are your opinion. Everybody has their own opinion on what is more readable. Sorry, but IMO it sounds like you aren't trying to make a standard that helps everybody, you're trying to make a standard that helps you. Sorry, but I'm calling b.s. on this. You say you've had decades of experience in coding. Now I don't disagree that you've probably had to first go reformat some of the bigger things like someone putting 100 things on one line, or lack of indentions, etc.. but if after decades of experience coding you can't make heads or tails out of code unless there's a space between some commas or parens in a given expression... IMO that doesn't add up. That's like saying you're an editor of a publishing firm a teacher at a school..been reviewing/grading writings for many years, yet having to reformat submitted books or turned in written assignments before being able to figure out wtf is written. That just doesn't happen. With experience, you know what you're reading about, even if the grammar/syntax is "improper". That's the difference experience makes. Soo...either you don't have the experience you claim to have, or if you have been doing it for that long, maybe you aren't the person should be writing standards. Just sayin'... Have you actually tried using a modern IDE with syntax highlighting, bracket matching, etc..? You can understand the code more easily because of these features. The whole point you're trying to make as far as spacing is being able to quickly scan for breakpoints etc.. so that you can get that out of the way and start understanding what the code is actually doing. I don't know about you, but when an editor automatically highlights that breakpoint for me...that's a lot more visual than scanning for a blank space - especially when you're also having to mentally filter out the non-relevant spaces when scanning it "traditionally." I think overall you're missing the point, and again, no offense but TBH I think it's because (IMO) you aren't really looking at it from a "what makes things easier for everybody" perspective, but what's easier for you. Nobody is arguing that these "standards" of yours is easier for you. We're simply arguing that different "standards" are easier for different people, and you should not try to standardize something this granular. As previously stated, I advise you stick with the bigger formatting "issues" such as commenting, bracket placement and indentions, but if you are somehow required to be specific about even spacing...there is no debate about what you should use: go with what has already been established as the "standard", not what you personally think is best. Again, not saying you are wrong for having your own idea of what's easier to read. I'm just sayin' you're wrong for making this about you.
-
That too. If your ultimate goal here is to make code more readable...you wouldn't be trying to shove everything into one line like that in the first place.
-
Although I see different spacing conventions all over the place for this...I've never really heard people argue over this spacing, and TBH IMO people will probably think you are being a bit anal for asking to adhere to a standard that granular. As far as formatting, IMO the only things you should try to standardize are a) comments b) indention c) bracket placement Having said that, if you for whatever reason absolutely must write and enforce standards for something you rightfully call trivial, here are my 2 cents: I don't think this is absurd, I think it is true. When I create a function, I generally try to order the arguments by importance and/or whether or not they are optional. So by that convention, the first argument is more associated with the function (in purpose, but also in name, since you usually name your function something having to do with its purpose, and arguments passed are also named in such fashion). But note that I'm only mentioning a counter-argument because you brought it up; I personally think that while naming conventions and argument positions make for more readable code, you're arguing about spacing here, which is kind of a different argument... IMO I will sometimes agree with this. TBH my spacing changes, depending on the actual code. If it is a single line like in your example, I might be inclined to put a space between the parens like that. But if it is part of a larger bit of code, IMO the more readable thing would be to not space it, and put a space between the closing bracket and next bit of code. But anyways, the problem is that it boils down to personal opinion. Different people have different ideas of what is more readable. Also, let's not get confused here... spacing does not produce "better code". PHP (and most other parsers/compilers) for the most part does not give a damn about it. It *might* lead to more efficient programming / time management because it *might* make it more readable, easier for new coders to come in and get up to speed or whatever, but that is not the same as "better code". Anyways... So again, my first advice to you is to not nickel and dime this, stick to the bigger things. Failing that, my next advice would be...sure, you could get all philosophical about how progress doesn't happen without going against the grain or something, but do you really get paid enough to set and fight for new "worldwide" standards...in some random organization? Think about that for a minute, and the choice should be obvious: go with what the "rest of the world" does. From the other coders the only feedback you will get is more or less what I'm telling you now: it's a matter of opinion and trivial. From non-coders you will have to defend why it is you somehow think your opinion outweighs the rest of the world, and in my experience, all they hear is "blahblahblah" because they aren't coders.
-
php freaks sopa/pipa acknowledgement
.josh replied to AyKay47's topic in PHPFreaks.com Website Feedback
exactly. Since they want to put the burden of proof is on the website owner, they can just see someone talking about it and shut them down until proven otherwise.