-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
Fair enough. I do agree that even though she's the one carried our kids in her tummy, it's not like I was sittin' there doin' nothing. All I'm saying is...spend 10m w/ Phil before you judge. Of course, I supposed people would say the same about me...albeit prolly for different reasons...
-
I just want to point out that considering Philip is technically a man, he's not going to come back pregnant. Just sayin'.
-
you have an infinite loop: while ($row) {
-
okay so the problem goes back to what i kinda mentioned as a sidenote in my tl;dr: Since you are passing a string to the RegExp() method, you have to consider characters that are escaped, because certain characters signify special things when you escape them in a string. For this pattern: var pattern = new RegExp('^[a-zA-Z]{5,6}\s'); ^ match for start of string [a-zA-Z] any letter (upper or lowercase) {5,6} 5 or 6 of that previous char class (so together, any combination of letters 5 or 6 characters long) \s this has no special meaning in strings, so the string is parsed as a literal "s", not the shorthand "whitespace" character class you expected. So IOW you are really passing '^[a-zA-Z]{5,6}s' to RegExp(), so it expects 5 or 6 letters followed by a literal "s". For this pattern: RegExp('^[a-zA-Z]{5,6}\b') ^ match for start of string [a-zA-Z] any letter (upper or lowercase) {5,6} 5 or 6 of that previous char class (so together, any combination of letters 5 or 6 characters long) \b This has special meaning to strings, it signifies a backspace character, so you are telling your pattern to look for a backspace character, not the shorthand "word boundary" character class you expected. To fix both of these, you must escape the escape: \\s and \\b. This will tell the string parser to use a literal backslash instead of trying to look for its special chars, so that when the string gets passed to RegExp() it will have the shorthand char classes you expect to pass it. Sidenote: With a regex object literal, you don't need to do this (ex: you don't need to do this, and in fact, this will not work as expected: .match(/^[a-zA-Z]{5,6}\\s/). Instead, you do it like normal: .match(/^[a-zA-Z]{5,6}\s/)) because you are working with an object literal not a string.
-
Weird...seems to me that if anything, as technology progresses and we can communicate better with people around the world, time zone difference become more prominent... for example, I work from home CST, company's main office is in EST, we have clients all over the world...when trying to setup meetings, time is always an issue because people live all over the place. .. got this one client in ireland always wanting to have mtgs bright in the early in the morning their time and i'm like fuck you, i'm still sleeping, lol
-
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.
-
we do. We're not here to help people rip other people off.
-
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
-
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
-
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 :/
-
@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?
-
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?
-
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?
-
Method not getting the inputted string?
.josh replied to yoursurrogategod's topic in Javascript Help
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 -
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.
-
geez, why so many pics? you work for a pr0n site?
-
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.
-
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.
-
swap out the part of your regex that matches the name, with the regex ChristianF gave you. Do you know which part of your regex matches the username? Were you the one who wrote this code?
-
Checking to see if at least one checkbox is checked?
.josh replied to galvin's topic in Javascript Help
alternatively, just use the same selectors and attach a .click event to it... $('#form input[name="checkedboxes[]"]').click(function() { alert($(this).val()); }); -
fast forward about 5 hours and you post the same thing here: http://www.codingforums.com/showthread.php?t=269246 saying you still have 1 hour before you have to submit? Get off your lazy ass and make an effort. People like you make people less willing to help others. If you don't like or want to do programming, why are you wasting yours and everybody else's time and money etc.. on going to that class? Grow up.
-
Checking to see if at least one checkbox is checked?
.josh replied to galvin's topic in Javascript Help
<script type='text/javascript'> $(document).ready(function() { $('#form').submit(function() { if ($(this).find('input[name="checkedboxes[]"]:checked').length == 0) { alert('make at least one selection!'); return false; } }); }); </script> -
Checking to see if at least one checkbox is checked?
.josh replied to galvin's topic in Javascript Help
does your page have a framework like jQuery on it? -
Deprecated: Function eregi() is deprecated (Line 18)
.josh replied to TottoBennington's topic in PHP Coding Help
deprecated doesn't mean you can't use it, it means it's advisable that you stop using it because it will eventually go away and not be supported in future versions of php. -
scootah is pregnant? Wait I thought she was a he?