Jump to content

requinix

Administrators
  • Posts

    15,229
  • Joined

  • Last visited

  • Days Won

    427

Everything posted by requinix

  1. I can explain them. First one is pretty simple: - () capture - [^]+ one or more characters that are not - \pL Unicode characters that are classified as "letters" - \' or apostrophes - /u flag to enable UTF-8/Unicode mode preg_split() would normally work like explode(), but with the PREG_SPLIT_DELIM_CAPTURE flag it also returns anything captured. Thus the explanation in the comments. Second is longer but really not that much more complicated: - [\pL\']+ A word consisting of Unicode letters or apostrophes - [^\pL\']+ Things that aren't letters or apostrophes (like spaces or periods) - {$n-1} Repeat those $n-1 times - [\pL\']+ The last word $1 will be all but the last word. By default it would also remove a string "0" because that ==false. You'd have to use a callback function to actually do $word == "". Right, but what if one of those words were being replaced? "A very short sentence." would become "A MOD short MOD" - no more period. You'd have to detect that period (or comma, or exclamation point, or...) and add it back in. Anything but letters and apostrophes. They're non-word characters which means they also act as word separators. Arguably hyphens could be included in there too, like how "non-word" is either one word or two depending how you look at it, except hyphens are used for a lot more than that so you'd need more sophisticated logic like "hyphens are considered word characters if they have a letter on both sides, otherwise not" which would suck.
  2. That. The rest of the indentation is 4 spaces but that line has 6, and the error message has a couple extra spaces before the function name.
  3. Best way is to build a list of all conditions to apply. conditions = array() if gender is provided { conditions[] = gender is <value> } if religion is provided { conditions[] = religion is <value> } if language is provided { conditions[] = language is <value> } if caste is provided { // probably should be combined with the religion one instead conditions[] = caste is <value> } if state is provided { conditions[] = state is <value> } if employment is provided { conditions[] = employment is <value> } if mstatus is provided { conditions[] = mstatus is <value> } if agefrom and ageto are provided { conditions[] = age between agefrom and ageto } query = SELECT ... if conditions { query .= WHERE implode(AND, conditions) }If the age thing can be open-ended then it's a little more complicated: if agefrom or ageto are provided { if agefrom and ageto are provided { conditions[] = age between agefrom and ageto } else if agefrom is provided { conditions[] = age greater than or equal to agefrom } else { // ageto is provided conditions[] = age less than or equal to ageto } }Also works fairly well if you need to conditionally join in other tables. For age specifically, figure out what the dates are rather than figuring out a person's age. With SQL it's as simple as birthdate BETWEEN CURDATE() - INTERVAL agefrom YEAR AND CURDATE() - INTERVAL ageto YEARor with PHP $date = date("Y-m-d", strtotime("-{$n} years"));
  4. There are 10! ways of combining all drivers with all cars. There are 100 ways of combining one driver with one car. You're both right.
  5. Actually it's something else. Using "localhost" clues the MySQL driver to use a socket, which is practically a file on the machine. Using "127.0.0.1" forces a TCP connection, which should definitely work. So your mysqld server daemon may not be creating the socket with the right permissions. Check your MySQL setting to see what it's doing. Also find the socket file itself - it probably doesn't have read (or execute?) permissions set for your user. Simply restarting MySQL may fix it too.
  6. Space alone isn't enough if you want to be really pedantic. There's other symbols to consider, like periods at the end of sentences, that would be lost if you didn't be sure to insert them back in. If there are two spaces then explode() will return an empty string between them. "Explode"ing on non-word characters is the next step, but that's too sophisticated for explode() to handle. You'd need regular expressions. And then you'd need to capture what you "exploded" on so you'd be sure to keep track of it. And now you've arrived at the preg_split() option I gave
  7. Resolve what? You've described what it is doing, uploading one file at a time, but not why that is a problem.
  8. Alright, based on those byte ranges it looks like you're aiming for just letters. You can do them all with Unicode, but I suggest you include apostrophes in there too (for contractions): /[\pL']+/uThe preg_split method is a bit tricky to wrap your head around, but the code is simple: $words = preg_split('/([^\pL\']+)/u', $alltext, -1, PREG_SPLIT_DELIM_CAPTURE); $replace = "MOD"; $n = 2; // every second word $i = ($n - 1) * 2; // $words includes the words *and the spaces*, alternating, because you'll need the spaces when you implode() it back together // [0] is a word, [1] is a space, [2] is a word, and so on // [0], [2], [4], ... is every word ($n=1, 0+2i), // [2], [6], [10], ... is every second word ($n=2, 2+4i), // [4], [10], [16], ... is every third word ($n=3, 4+6i), // or another way, [($n-1)*2 + ($n*2)i] $wordcount = count($words); for ($i = ($n - 1) * 2; $i < $wordcount; $i += $n * 2) { $words[$i] = $replace; } $words = implode('', $words);The preg_replace() version is just as simple but the regex is a bit longer: count out $n-1 words and spaces, capture that, capture the last word, then replace the lot with the capture and your replacement word. The advantage is that you have preg_replace() doing all the work for you. $replace = "MOD"; $n = 2; // every second word $words = preg_replace('/(([\pL\']+[^\pL\']+){' . ($n - 1) . '})[\pL\']+/u', '$1' . preg_quote($replace), $alltext);
  9. It's not anywhere in that code. Where did you try to put it? What was that code?
  10. Use preg_split() to split the sentence into words, run a loop that replaces every other word, then implode() it all back together. Translating the $pattern you have now into one that matches non-word characters will be easier if you can tell me what Unicode ranges you're trying to match. Which, by the way, is done much more easily with the actual Unicode support that PCRE has instead of constructing the bytes yourself. Or preg_replace() every pair of words with the first word + the replacement. Again, the regex will be a lot nicer if you use PCRE's Unicode support.
  11. It's probably making a loop. Add an [R] flag and see where you're being redirected to. You may need your browser's console, or an extension, to see the traffic if the URL isn't changing. And to be sure, what's your full .htaccess now?
  12. Stop using @ error suppression. You should get an error message now: $dbh = mysql_connect($dbhost, $dbuser, $dbpass); if (false === $dbh) { $err = mysql_error(); if ($triggerError) { throw new Exception("Could not connect to db: $err\n"); } } [edit] For whatever reason, indentation isn't working. [/edit] Also, try using $dbhost = "127.0.0.1", see if that makes a difference. And there is no such thing as PHP 5.7.
  13. MySQL doesn't have a message that says "Permission denied". What's the rest of the code?
  14. RewriteRule ^page/item/(\d+)$ page/item.php?id=$1 [L,QSA]There's no point omitting the .php here as the user won't see it and it would make Apache work that much harder to route the request.
  15. Does the error page mention WebDAV anywhere?
  16. jQuery. Or another Javascript framework. You're getting into the realm of things that are awkward and tedious to do in plain Javascript. For example, what you're looking for in jQuery is done with $(".testclass").html("result here");
  17. For crying out loud, how can it be so difficult to explain this... Let's try pure algebra. Can you handle algebra? I hope so. Some variables: B = bet amount O = odds of winning P = net profit W = amount paid out to the winner Some equations: P = W - B (profit is the winnings less the bet amount) W = B * O + B (winnings is the bet amount paid out by the odds, plus the original bet back) Let's combine those two equations: P = (B * O + B) - B P = B * O Okay? So the net profit is the bet amount multiplied by the odds. Now let's rearrange it so that the equation solves B (what you want to know) in terms of P (a known amount) and O (also a known amount). B = P / O Now let's plug in some values. P = 30 O = 5/2 = 2.5 B = 30 / 2.5 B = 12 What is not clear about that?
  18. You keep saying $42 but the question, as far as I can tell, has always been "what is the bet amount to get a profit of $30?" Which bsmither and I have both told you is simply profit / odds. The fact that he receives $42 is moot.
  19. $12 is right... Not sure what the $42 is for? Profit of $30, which means 2.50 * $bet = $30. Because you can ignore the +$bet part because that's just him getting his money back. 30 / 2.50 = 12.
  20. What keys do you have on that table? Do a SHOW CREATE TABLE $table if you're not sure. More than one key? Sounds like you're violating one key (that isn't the description), triggering the ON DUPLICATE KEY, but then violating the description key with the new value.
  21. "Until 1 post" would probably be fine. I wouldn't go for the "until X days" because I've seen spammers sign up days, even months in advance of their first post.
  22. Registration CAPTCHA broke. It's disabled for now but they're trying to fix it.
  23. Yes, in general (depends if your hosting allows it), but there are very few reasons why you should ever do that. What do you need it to do?
  24. I suggest actually learning PHP so you'll understand what the code is doing and can figure out answers like "remove the parts you don't want" on your own. echo $ImStore->get_permalink( "shopping-cart", true, false, $post->post_parent );
  25. Those figures only show anything if there is a PHP process running at the very same second you get to that page. For a low-traffic site that may be a rare occurrence. Create a script with something like a sleep(100) so it runs for a long time, go to it in your browser, and reload the CPanel page.
×
×
  • 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.