Jump to content

requinix

Administrators
  • Posts

    15,227
  • Joined

  • Last visited

  • Days Won

    427

Community Answers

  1. requinix's post in Find n in algorithm was marked as the answer   
    Alright.
     
    Use a DateTime for the chosen date and diff it to starting date. That will give you a DateInterval which can tell you how many days are between the two dates. Since you don't care about the number of cycles between the two dates (k from before) all you have to do is use modulus to get the day number (d). Which needs a bit more of an explanation.
     
    Say the diff is 108 days. The most obvious course of action is to +1 (because the starting date is day #1 and not day #0) and %15 to get 4. That's not quite right.
    Say the diff is 14 days. Smaller number. +1 is 15 and %15 is 0. That's not right: you need to get 15 and not 0. You could say "if result == 0 then result = 15" but there's an easier way:

    ($diff % 15) + 1What you're actually doing is taking the diff, +1 because of the starting date, then doing a trick where you -1 then %15 then +1. Watch:
    (14 % 15) + 1 = 15which is the result you wanted. And
    (108 % 15) + 1 = 4like before. 

    $pattern = 15; $start_date = new DateTime("2015-12-14"); // day 1 // Day 15 = 2015-12-29 $chosen_date = new DateTime("2016-03-30"); $difference = $chosen_date->diff($start_date)->days; $day_number = ($difference % $pattern) + 1; If($day_number == 13 || $day_number == 15) { Echo "possible outcome. Day $day_number."; } Else { Echo "not possible, day $day_number"; }
  2. requinix's post in Mail function not working was marked as the answer   
    There is so much more to doing emailing properly, and so many ways it can go wrong.
     
    Do yourself a favor and get yourself a copy of PHPMailer. (There are other things but it's the most popular.) There are tons of examples and plenty of documentation on how to use it, and it will take care of everything for you.
  3. requinix's post in Can PHP do all of this image manipulation? was marked as the answer   
    Using strictly PHP and GD? Well yeah, sure it's possible, but here are all the GD functions available to use and none of them do what you want. Meaning you'd have to do the edge detection* or masking yourself.
     
    Bite the bullet and use something like ImageMagick instead. It does come as a PHP extension but more commonly you invoke the command-line program. It's powerful and I'm sure it can at least do the second method, if not both.
     
    * GD can do edge detection, where it creates an image showing edges, but it won't work for arbitrary points on an image so you couldn't rely on it.
  4. requinix's post in frmvalidator.addValidation regexp for a line break? was marked as the answer   
    \r and \n are easier than the \u syntax, but they'll be interpreted by Javascript and you'll get those characters inside the actual string.
    Escape the backslashes like "\\r\\n".
  5. requinix's post in xml parse was marked as the answer   
    $entry is only an . There is no and such in it. You have to go down into the to get those.

    foreach ($xml->entry as $entry){ $Fnum=$entry->content->{'filing-type'};
  6. requinix's post in moving a file to another directory was marked as the answer   
    "The file input"?
     
    rename (which does moves too)
    Figure out the path to the file in directory A, figure out the path you want it for in directory B, and pass both to rename().
  7. requinix's post in Mail issue leads to need for complex str_replace? was marked as the answer   
    You also need to be putting $new_recipient back into the array, not the original $recipient.
     
    Another thing. Keep in mind that strpos() can return 0 if the string starts with a @. And 0 == false. So you'd get something like "@foo@xyz.com". The alternative is "@foo" (looks like an email so don't change it), which isn't good either but it would probably be better to keep that. So use === false for an exact comparison.
  8. requinix's post in Global functions in OOP with class support was marked as the answer   
    Just use a normal, plain, simple function. Like in your first example. OOP is about object entities, not about using classes for everything.
     
    The reason it doesn't work is because the "Log" that you are use-ing in Main.php does not apply to functions.php too. It's a per-file thing. So

    //functions.php use Company\Project\Handlers\Log; function __log_notice(string $text) { Log::notice(0, $text, true); }or
    //functions.php function __log_notice(string $text) { Company\Project\Handlers\Log::notice(0, $text, true); }
  9. requinix's post in Delete my Account was marked as the answer   
    Ooh, scary.
  10. requinix's post in Can you delete my account please? was marked as the answer   
    Posting something so I can mark this as solved.
  11. requinix's post in How do I delete my account? was marked as the answer   
    We don't like deleting accounts, but I can "suspend" you so your account is no longer active.
  12. requinix's post in php56 installation was marked as the answer   
    So no. 
    But the PHP Installation & Configuration forum sure sounds appropriate.
  13. requinix's post in xml http request was marked as the answer   
    AJAX is asynchronous - it does not happen linearly with the rest of your code. web_socket_open() will finish executing immediately and then eventually sometime later the onreadystatechange function will fire. Nevermind that the return will only return from that anonymous function and not web_socket_open().

    function web_socket_open(href){ var request = new XMLHttpRequest(href); request.onreadystatechange = function() { if (request.readyState === 4 && request.status === 200) { console.log(true); } console.log(false); } } web_socket_open('http://127.0.0.1:8080');And notice that if everything is good you'll see a true and false output.
×
×
  • 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.