Jump to content

requinix

Administrators
  • Posts

    15,067
  • Joined

  • Last visited

  • Days Won

    414

Everything posted by requinix

  1. Why bother encoding it if you're just going to decode it?
  2. $data is a string. You can't do ->items on it.
  3. If you want true Word docs then I'd mention phpdocx. Not free. At my work we needed to convert HTML into something editable for our users to download, checked out options, and went with phpdocx. Does the job well enough. However, if you're running PHP from a Windows box, and don't have a problem installing Office on it too, then you can use COM to "script" Word into opening up HTML files and re-saving them.
  4. Your form is sending the data to the thank you page. For validation to work the form must be sending the data to the page where the validation is running. So a) Make your form page do the validation (which it's doing now) as well as process the form b) Make your form go to the thank you page (which it's doing now) and have the thank you page do the validation (a) is easier because (b) means that you have to find a way to shuffle the data from the thank you page to the form in case of problems.
  5. It is executing in the proper order: https://3v4l.org/7lALJ.
  6. Please don't. You'll encourage me to never post stuff like that again. I only ever use it with really, really simple stuff. Like $variable && function_call($variable);or isset($array["value"]) && $obj->property = $array["value"];You can see what it's doing at a quick glance. No thinking involved. That thing with the regex and the list() is too complicated: you have to think "okay, what is preg_match() returning and what are the values in $match and why is list() skipping the first array value" and it's just a hassle.
  7. Don't use it as a matter of practice. It's just a clever way of doing two commands at once; if the regex failed then $ip and $port would be undefined. You know $x && $y? $y doesn't get evaluated unless $x is true, and if $x is false then it does not. And since preg_match() returns 1 (which is "true") if it matches, the assignment only gets evaluated if the regex matched.
  8. Because the code on your machine is not the exact same code you posted here. Even more so because FatalErrorException is not a built-in class to PHP, which means there is some other code somewhere that defines and throws it.
  9. The code you have posted executes just fine: https://3v4l.org/VgRDX
  10. Here's a quick one: preg_match('/^(.*)\d+)$/', "2001:db8:a0b:12f0::1:25", $match) && list(, $ip, $port) = $match;(I was deliberately avoiding doing this with my first answer)
  11. Do you mean, like, where is the most appropriate place in code to set it? There isn't anything in there that's clearly "this is a point where the user has chosen a particular language", but the closest would be where you check $_GET. if (isset($_GET['language']) && self::is_language_supported($db, $config, $_GET['language'])) { // setcookie(...) return $_GET['language']; }
  12. Not being able to think of any nicer solution, I'd go with substr() and strrpos(). $ipport = "2001:db8:a0b:12f0::1:25"; $p = strrpos($ipport, ":"); $ip = substr($ipport, 0, $p); $port = substr($ipport, $p + 1);
  13. Then the error message is incorrect. Or the error message is referring to some other code that isn't what you posted.
  14. That is not possible: (1) the index is actually "sessionvar" and (2) you did an empty check just before. What is your real code?
  15. Then it's easy to change the script. Right now it tracks just the coldest and hottest temperatures; add two more variables for the coldest and hottest locations.
  16. FYI, next time you post code, make sure you remove sensitive information like the appid you had in that URL. So that code makes more sense than the one earlier, and doesn't have as much that needs to change. You already have a loop that goes over all the locations, so do the work of determining the highest and lowest in there. Do you only care about the temperatures? You like you don't care where the temperatures are from - just what they are? <?php session_start(); include_once("cxn.inc"); $today = date("Y-m-d H:i:s"); $sql = "SELECT airports.Name,airports.Country FROM airports INNER JOIN rosters ON airports.IATA = rosters.Arr WHERE rosters.Code = '$code' AND rosters.SectorDate >= '$today'"; $result = mysqli_query($cxn,$sql) or die ($cxn->error); $coldest = $hottest = null; while($row=mysqli_fetch_assoc($result)) { $link = 'http://api.openweathermap.org/data/2.5/weather?q='.$row['Name'].','.$row['Country'].'&units=metric&mode=xml&appid=*'; /* WEATHER API */ $xml=simplexml_load_file("$link") or die ("Cannot create object."); $temp = (int)$xml->temperature['value']; // converting to int is important or you'll have a bunch of SimpleXMLElement objects if (is_null($coldest) || $temp < $coldest) { $coldest = $temp; } if (is_null($hottest) || $temp > $hottest) { $hottest = $temp; } } /// OUTPUT GOAL /// echo $coldest; echo '<br />'; echo $hottest; ?>
  17. Alright, then we need to start from the beginning. What is the XML you have ($link?) and what does the database have to do with it?
  18. Your code doesn't make sense. Is that really what you have?
  19. How do you want the user to decide? Do you want them to give them both options at once? Have some sort of "custom" item in the list? For the list itself, a simple for loop will do: echo "<select>"; for ($m = 0; $m <= 24; $m += 0.25) { $hhmm = sprintf("%02u:%02u", floor($m), (60 * $m) % 60); echo "<option value='{$hhmm}'>{$hhmm}</option>"; } echo "</select>";
  20. Turn everything into a int, like using array_map with intval, then do min() and max() on the final array. Looks like you're getting this from XML? You might be able to do the min/max from within the XML itself, depending on what the markup is...
  21. If someone has access to the system then you're done for. Basic tenet of computer security. Obfuscating, hashing, compiling code, none of that will protect you for long. If this information is so secretive that you don't want these people with access to be able to see it then don't give them access. It's that simple.
  22. You're running some kind of update script on a database that doesn't need updating.
  23. Huh. I must have missed the changelog entry that says "file_get_contents() will now attempt to execute what it retrieves as PHP code".
  24. Yes. Using some Mail class, not vanilla mail().
×
×
  • 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.