Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. so like, I was using hardcoded values as an example since I don't have access to make the curl request like you do. Your code generates $result from the curl request, so just remove my $result =<<<EOR..EOR; example data.
  2. $result = <<<EOR [ {"PartID":456,"Category":3,"Status":"another status","Timestamp":"99999"}, {"PartID":123,"Category":5,"PartNumber":1267,"Description":"blabla....","Status":"some status","Timestamp":"123456789","Datasheet":"some value"}, {"PartID":456,"Category":2,"Description":"some description","Timestamp":"99999"} ] EOR; $data = json_decode($result, true); $header = array(); foreach ($data as $jsons) $header = array_values(array_unique(array_merge($header,array_keys($jsons)))); echo '<table border="1">'; echo '<tr><th>'.implode('</th><th>',$header).'</th></tr>'; foreach ($data as $jsons) { echo '<tr>'; $row = array(); foreach ($header as $h) $row[$h] = (isset($jsons[$h])) ? $jsons[$h] : ''; echo '<td>'.implode('</td><td>',$row).'</td>'; echo '</tr>'; } echo '</table>';
  3. $result = '[{"PartID":123,"Category":5,"PartNumber":1267,"Description":"blabla....","Status":"some status","Timestamp":"123456789","Datasheet":"some value"}]'; $data = json_decode($result, true); echo '<table border="1">'; echo '<tr><th>Part Number</th><th>Description</th><th>Status</th><th>Timestamp</th><th>Datasheet</th></tr>'; foreach ($data as $jsons) { echo '<tr>'; echo '<td>' . $jsons['PartNumber'] . '</td>'; echo '<td>' . $jsons['Description'] . '</td>'; echo '<td>' . $jsons['Status'] . '</td>'; echo '<td>' . $jsons['Timestamp'] . '</td>'; echo '<td>' . $jsons['Datasheet'] . '</td>'; echo '</tr>'; } echo '</table>';
  4. Okay, maybe you are trying to "simplify" things for me, and there's more code at play that's somehow not right? Because your first code snippet: preg_match('~(I HAVE HAD ENOUGH)(.*?)(THIS HEADACHE)?$~','I HAVE HAD ENOUGH OF THIS HEADACHE OK',$m); var_dump($m); Returns this: Array ( [0] => I HAVE HAD ENOUGH OF THIS HEADACHE OK [1] => I HAVE HAD ENOUGH [2] => OF THIS HEADACHE OK ) So firstly, the returned results don't match what you've posted. 2nd, (THIS HEADACHE)? will not match, even with the $ on the end. Why? Because your string doesn't end in "THIS HEADACHE". It ends in "THIS HEADACHE OK". However, you will see that [2] shows the rest of the string because the (.*?) will match the rest of the string to satisfy matching the $ on the end. If you want to make it optionally match for "THIS HEADACHE" when it is not the end of the string, you will need to group the .*? and (THIS HEADACHE)? together: preg_match('~(I HAVE HAD ENOUGH)(.*?(THIS HEADACHE))?~','I HAVE HAD ENOUGH OF THIS HEADACHE OK',$m); var_dump($m); This will match: Array ( [0] => I HAVE HAD ENOUGH OF THIS HEADACHE [1] => I HAVE HAD ENOUGH [2] => OF THIS HEADACHE [3] => THIS HEADACHE ) Actually, here is another example of where greedy vs. non-greedy come into play. With this example, using (.*) instead of (.*?) will give you the same result. However, the (.*) will be more efficient. HOWEVER, if your string is more complex and has more than one occurance of "THIS HEADACHE", (.*) will consume up to the last occurrence of it, whereas (.*?) will match up to the first occurrence of it. Also, you can make the outer parens a non-capture group to cut down on the returned results. Example: preg_match('~(I HAVE HAD ENOUGH)(?:.*?(THIS HEADACHE))?~','I HAVE HAD ENOUGH OF THIS HEADACHE OK',$m); var_dump($m); will return Array ( [0] => I HAVE HAD ENOUGH OF THIS HEADACHE [1] => I HAVE HAD ENOUGH [2] => THIS HEADACHE )
  5. you said you have 7 brokers to cycle through, but your $brokers array only has 2 links in them..
  6. Okay, so this: preg_match('~(foo)(.*?)(bar)?~','foo bar',$m); will give you this: Array ( [0] => foo [1] => foo [2] => ) [0] is the full pattern match[1] is from (foo) [2] is from (.*?) Okay so (.*?) matches nothing, not even the space, because it is non-greedy and therefore matches for nothing. So, the pointer is currently at the space between "foo bar". So (bar)? is greedy, but won't match, because "b" != " ". Since there's nothing else to match for, that's all you get. Now from your other thread, where a $ was thrown onto the end: preg_match('~(foo)(.*?)(bar)?$~','foo bar',$m); will give you this: Array ( [0] => foo bar [1] => foo [2] => [3] => bar ) Aha, now this is where things get interesting. Since there is something after the (bar)? that HAS to match (the $), the engine now has to backtrack to match for it. Why? because the next characters after "foo" are " bar" not end-of-string. So it can't just match "foo" as if "foo" is at the end of the string. Now there are 2 ways this can happen: 1) match a space " " with (.*?) and "bar" from (bar)? 2) match " bar" with (.*?) (in which case (bar)? doesn't match for anything) Well the regex engine goes for option #1 because it's the path of least resistance. Remember, (.*?) is still lazy, so it's only going to match what it has to. Since (bar)? doesn't match for a space, (.*?) MUST match the space, in order to satisfy the $ match. And since (bar)? is greedy and can fill in the rest of the blanks, that is used. More accurately what happens is that it's backtracking from end of string one character at a time to fill in the blanks between "foo" and end of string. IOW it's moving backwards to come up with " bar". Well the first thing it runs up against is that (bar)? and it matches that, and now all it needs is the space, so then it backtracks some more and can fulfill it from the (.*?) So in the first example, [2] is an empty string, but in the 2nd example, [2] is a space " " I know, it's pretty confusing, and takes some getting used to, and to fully understand it, you have to dive into how the engine works, not just what the symbols do. There's a reason regex has a high learning curve and few people dare to climb that mountain!
  7. I don't have any experience with xrumer but it would have to either be a browser addon/extension that works on the the page with the form, or else it is a program making requests to the domain (and still) acting within that domain's scope. For example, if you made a server-side script (or a standolone program with java or c++) that can request the page and store cookies etc. and essentially act as a browser, and then start looping through it, then it is possible, because it is acting within the scope of the page. IOW this can easily be done with a server-side script (e.g. php, perl) or standalone program (e.g. java, c++). Javascript cannot do this alone though. Javascript can only act on pages on the same domain (read up on same domain origin policy and cross-site scripting). And btw, no offense but I do not put people trying to do this sort of thing in the same bucket as me. Also, it's pretty disrespectful to write a whole city off as being stupid. There are many brilliant people who do not program. Even farmers. You do know it takes skill to farm the right way, right?
  8. No. Once the form is submitted, the entire page reloads with the response from http://someweb.com. Javascript does not carry over like that. If you want to make it "remember" and continue through the loop, you will need to base the loop on cookies, or else base it on variable output by the server response from http://someweb.com. Both are only possible if http://someweb.com is the same page you are already on (IOW the same as just doing action='') Alternatively, you can convert it to an ajax request to keep it on the same page and loop, however again, this will only work if the requested page is the same domain as the requesting page.
  9. Okay well then maybe you should post what your actual problem is. "Asking questions 101 (circa 1969): State the actual, complete problem, not some subset or tangent of the problem. 'Dumbing it down' rarely works out. If you had the ability to accurately 'dumb it down,' you likely wouldn't be stuck with trying to fix the problem in the first place!"
  10. I agree with requinix.. you're not making a whole lot of sense here, and providing actual example(s) of what you want to happen would be a lot more helpful. But it sounds like what you want is already how the engine behaves. It sounds like you want it to match something, and only match nothing if it has to (to fulfill the rest of the pattern). Well that's exactly how it already works with the * quantifier, and the ? when used as a quantifier (not a non-greedy flag). Examples with 0 or more * quantifier: $string = "foobar"; preg_match('~(\w*)~',$string,$m); // $m[1] contains "foobar" preg_match('~(\w*)(\w)~',$string,$m); // $m[1] contains "fooba" // $m[2] contains "r"; preg_match('~(\w*)(oobar)~',$string,$m); // $m[1] contains "f" // $m[2] contains "oobar"; preg_match('~(\w*)(foobar)~',$string,$m); // $m[1] contains "" // $m[2] contains "foobar"; Same thing with the ? as a 0 or 1 quantifier: $string = "foobar"; preg_match('~(\w?)~',$string,$m); // $m[1] == "f" preg_match('~(\w?)(\w)~',$string,$m); // $m[1] == "f" // $m[2] == "o"; preg_match('~(\w?)(oobar)~',$string,$m); // $m[1] == "f" // $m[2] == "oobar"; preg_match('~(\w?)(foobar)~',$string,$m); // $m[1] == "" // $m[2] == "foobar"; The "summary" definition of a quantifier "matches "n or more.." can be a bit confusing when you don't read the fine print under it.By default, quantifiers are in a "greedy" state, and will consume everything they can. They will only give up what they have consumed if there is more to the pattern and that pattern cannot be satisfied unless they give something up. And they only give up exactly what they have to. So by default, it's more of a reverse situation, where it matches "everything it can or less". Also, it's worth pointing out that ? means 2 different things, depending on the context. If it is after a pattern to be matched (single char, char class, group, etc.), then it is a quantifier, meaning "match 0 or 1" of the thing before it. If it comes after another quantifier, it becomes the "make this quantifier non-greedy" flag. What does that mean? Well it (sort of) reverses the "greedy" behavior of the quantifier. Instead of eating everything in site and barfing up what it has to afterwards, it asks the rest of the pattern if it needs the next character and if it doesn't, then it consumes it. Then it moves on to the next, wash rinse and repeat until it comes to the first character its pattern can't match. So it's more of a "look before you leap" approach, effectively making it more accurate to the "match [n] or more" description. So why isn't non-greedy matching the default? Long story short, it boils down to efficiency. In most cases it's faster to make the pattern consume everything it can and then back-track, than to keep looking ahead at every character. But if you need to, you can make it the default by using the U modifier. This will reverse the behavior. For example.* will be non-greedy and .*? will be greedy. Seriously though, there is rarely a case where this will actually increase efficiency. 99.99% of the time it's just swapping syntax, which is only "useful" if you're trying for the "shortest possible pattern" award. If you are in a position of thinking it might help, then you should already be calling yourself a regex-master. If you you are not a regex-master, then at best you will just wind up confusing yourself (and others) trying to understand your pattern. I probably shouldn't have even mentioned it. Do yourself a favor and just delete this paragraph from your memory.
  11. use the jQuery library, will make your life a lot easier. Here is a jsfiddle example
  12. It's essentially the same thing. Both are apache redirect rules. The latter is just more of a convenience since handling certain response types is common.
  13. Also, your indentation is off. It's not necessary but would make the code clearer. For example, you probably would have caught the missing closing bracket if it was indented properly. This is what it should look like: $list=array(8,1,7,-7,2,4,5,-14,0,1); for ($i=0;$i<10;$i++) { $x=$list[$i]; if ($x=>4) { $total=$total+$x; $biggies++;//biggies=$biggies+1; } else if ($x==0) { $zeros++; } } print "The sum of biggies is $total . "; print "There were $zeros zeros and $biggies biggies."; A better way to write this: // good practice to initialize your vars $list=array(8,1,7,-7,2,4,5,-14,0,1); $total=0; $biggies=0; $zeros=0; // a foreach will iterate through the whole array without having to code in the array size // alternatively, you can use count($list) instead of hardcoding 10 if you want to stick to the for loop foreach ($list as $num) { // switch is more cleaner looking than if..elseif..elseif..etc.. switch (true) { case ($num>=4): $total+=$num; // shorthand operator for adding to itself $biggies++; break; case ($num==0): $zeros++; break; } // end switch } print "The sum of biggies is $total ."; print "There were $zeros zeros and $biggies biggies.";
  14. 1) You have your $list commented out. Uncomment it (remove the #). Also it should be $list not list also you are missing the semicolon at the end of it. 2) it should be for not $for (no dollar sign) 3) line 5: you need to use >= the instructions say greater than or equal to 4 4) you are using a ] instead of } on line 13 5) line 14 should use $total not $biggies 6) line 14 missing a closing quote and semicolon 7) you need another print that shows how many zeros and biggies. You already have the vars incremented..just print them out as a message 8 )you are missing a closing } at the end, for your for loop. this should come before your print statements
  15. alternatively, the keywords you can search for are "url beautification" or "seo friendly urls"
  16. something like <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  17. sounds like you need to set your content type to utf8 on your page.
  18. you get what you pay for.. also, this isn't a regex question; moving.
  19. i honestly don't know what the problem could be then.. did your video tag code work fine before, when it was pointing to the .mp4 directly, in the same directory?
  20. bad. bad. baaaaaaaaaaad. shoo.
  21. that is a whole new question and it's a javascript question, not a php question. Post a new question in the javascript forum.
  22. huh..well that's weird.. only reason I even went to this thread was cuz it was on the first page of the thread listing.. what trickery is this?!?
  23. Change your WHERE clause to .. WHERE category IN(57,58,59,60) .. This will select where the category is any of those values.
  24. Well that confirms my assumption but not the code. Nor did you respond to the stuff before that. Bottom line is I can't help you without knowing what you actually want.
×
×
  • 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.