Jump to content

leke

Members
  • Posts

    39
  • Joined

  • Last visited

Everything posted by leke

  1. Ah, it seems I had the wrong values for the months (now corrected) and after I corrected the seconds attribute, I'm now getting the correct results for the year/month/day
  2. Hi, Here are the problem parts of the form... <form action="contact_db/contact_submit_script.php" method="post"> <p>Time and date</p> <select name="dateMonth"> <option>Month</option> <option value="1">January</option> <option value="2">Febuary</option> <option value="3">March</option> <option value="4">April</option> <option value="5">May</option> <option value="6">June</option> <option value="7">July</option> <option value="8">August</option> <option value="9">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dateYear"> <option value="2011">2011</option> <option value="2012">2012</option> <option value="2013">2013</option> </select> <select name="timezone" id="timezone"> <option>TimeZone</option> <option value="-12.0">(GMT -12:00)</option> <option value="-11.0">(GMT -11:00)</option> <option value="-10.0">(GMT -10:00)</option> <option value="-9.0">(GMT -9:00)</option> <option value="-8.0">(GMT -8:00)</option> <option value="-7.0">(GMT -7:00)</option> <option value="-6.0">(GMT -6:00)</option> <option value="-5.0">(GMT -5:00)</option> <option value="-4.0">(GMT -4:00)</option> <option value="-3.5">(GMT -3:30)</option> <option value="-3.0">(GMT -3:00)</option> <option value="-2.0">(GMT -2:00)</option> <option value="-1.0">(GMT -1:00)</option> <option value="0.0">(GMT)</option> <option value="1.0">(GMT +1:00)</option> <option value="2.0">(GMT +2:00)</option> <option value="3.0">(GMT +3:00)</option> <option value="3.5">(GMT +3:30)</option> <option value="4.0">(GMT +4:00)</option> <option value="4.5">(GMT +4:30)</option> <option value="5.0">(GMT +5:00)</option> <option value="5.5">(GMT +5:30)</option> <option value="5.75">(GMT +5:45)</option> <option value="6.0">(GMT +6:00)</option> <option value="7.0">(GMT +7:00)</option> <option value="8.0">(GMT +8:00)</option> <option value="9.0">(GMT +9:00)</option> <option value="9.5">(GMT +9:30)</option> <option value="10.0">(GMT +10:00)</option> <option value="11.0">(GMT +11:00)</option> <option value="12.0">(GMT +12:00)</option> </select> </p> <input type="submit" name="submit" value="Send message" /> </form> The PHP code. I corrected the 3rd attribute of mktime(). $message = $_POST['message']; $message_br = nl2br($message); $LocationType = $_POST['locationType']; $dateDay = $_POST['dateDay']; $dateMonth = $_POST['dateMonth']; $dateYear = $_POST['dateYear']; $timeHour = $_POST['timeHour']; $timeMins = $_POST['timeMins']; $timeAMPM = $_POST['timeAMPM']; $userName = $_POST['name']; $timezone = $_POST['timezone']; $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, 0, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; I'm just reading through date_default_timezone_set() and seeing how I can add the timezone to the date()
  3. I'm practising how to do date and time in PHP. I wanted to see if I can get all of the date/time variables from user submission and format them correctly. I went with ISO 8601 date... // From the Manual: // date('c', mktime(1, 2, 3, 4, 5, 2006)); // Prints something like: 2006-04-05T01:02:03+00:00 ...but my attempts always produce a slightly different result for the year, month and timezone... $inputTime = date('c', mktime((int)$timeHour, (int)$timeMins, (int)$timezone, (int)$dateMonth, (int)$dateDay, (int)$dateYear)); echo $inputTime; // Should return: 2013-11-02T02:30:01+00:00 // Instead returns: 2012-12-02T02:30:01-08:00 The timezone value coming from HTML... <option value="1.0">(GMT +1:00)</option> I noticed; 1. It always picks a year less than whatever year I select. 2. It always selects 12 as the month. 3. It always adds -08:00 after the picking the correct timezone. How come? Thanks in advance.
  4. preg_match_all('/[\w\ŝ\ĉ\ĝ\ĵ\ŭ\ĥ\Ŝ\Ĉ\Ĝ\Ĵ\Ŭ\Ĥ]+|[\W]/', $form_submission, $matches); // $matches[0] array returns words that include accented characters. foreach ($matches[0] as $value){ if (preg_match('/\W/', $value)){ // check for any non-wordy characters in array. ... I'm checking for a word which might include a character like ŝ ĉ ĝ ĵ ŭ ĥ Ŝ Ĉ Ĝ Ĵ Ŭ Ĥ. This part of the code preg_match('/\W/', $value) is identifying one of the accented characters as a non-standard character and returning true. How could I make a match for '/\W/' but exclude ŝ ĉ ĝ ĵ ŭ ĥ Ŝ Ĉ Ĝ Ĵ Ŭ Ĥ ? Thanks in advance.
  5. Hi, I hope this is still a relevant topic here. I don't have a lot of coding experience and haven't studied it a college -- I'm just self taught hobbyist. I was wondering what your opinion is of the way I have structured my code and solved what I needed to do. Any tips or feedback is greatly appreciated. Thanks. <?php $form_submission=$_POST["query"]; $lines = file('eo_dic.txt', FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES); preg_match_all('/[\w\'\ŝ\ĉ\ĵ\ŭ\ĥ\Ŝ\Ĉ\Ĵ\Ŭ\Ĥ]+|[,.;!"?-\s\\(\\)]/', $form_submission, $matches); foreach ($matches[0] as $value){ // Check if $value is a word or something else. if ($value == " " || $value == "," || $value == "." || $value == "(" || $value == ")" || $value == "!" || $value == "?" || $value == "-" || $value == ";" || $value == '"'){ echo $value; } else { // $value is a word. $titleText = array(); // store results in array. foreach ($lines as $line){ list($field1, $field2) = explode('=', $line); if (strcasecmp($field1, $value) == 0 || strcasecmp($field2, $value) == 0){ // Found string in DB. array_push($titleText, "$field1 = $field2"); // Store all finds in array before outputting. } } if (empty($titleText)) { // $value was not found -- array is empty. echo '<a name="translated" class="translated" title="Not found.">' . $value . '</a>'; } else { $arrayOut = implode(" / ", $titleText); // output the results found in the search. echo '<a name="translated" class="translated" title="' . $arrayOut . '">' . $value . '</a>'; } } } unset($value); ?>
  6. I was still getting the error with... $line = str_replace("\n", "", $line); $line = str_replace("\r", "", $line); ...and also with just... FILE_SKIP_EMPTY_LINES or FILE_IGNORE_NEW_LINES ...but when I tried both FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES ...I didn't get any errors. The output looked like this, Brother = fratoBrotherhood = fratecoBrotherly = frata but I can fix that with some formatting I guess. It's pretty weird. I actually fixed all the empty lines I found in the text file(edit: whoops I missed some, so I guess it was the empty lines after all), but the errors still occurred until I added FILE_IGNORE_NEW_LINES and FILE_SKIP_EMPTY_LINES. I'll look at the manual for FILE_IGNORE_NEW_LINES and FILE_SKIP_EMPTY_LINES and see how they fixed the problem. Thanks for the help bud.
  7. Oh wait, I changed my console settings so it included unlimited lines and while I was scrolling through the dictionary, I discovered a empty lines where the script had errored. Just going through and correcting now.
  8. // I realized I didn't really need the sanitation part for the example... Ok, this... $form_submission = "brother"; $lines = file('eo_dic.txt'); foreach ($lines as $line) { echo "||||$line||||"; list($field1, $field2) = explode('=', $line); if (stristr($field1, $form_submission) || stristr($field2, $form_submission)){ echo $field1 . ' = ' . $field2; } } Returned this...
  9. Hi Ted, Thanks for the reply. Yeah, that made sense, so I used the explode function (which returns single array ), but get the same error as a result
  10. Hi, I'm testing my PHP in the console and was wondering what this means? PHP Notice: Undefined offset: 1 Is it a warning or an error? My code... $form_submission = "brother"; $lines = file('eo_dic.txt'); if ($form_submission == null){ // Sanitization. echo 'Text field is empty!'; exit; } foreach ($lines as $line) { list($field1, $field2) = preg_split('/=/', $line); // back slash might not be needed if (stristr($field1, $form_submission) || stristr($field2, $form_submission)){ echo $field1 . ' = ' . $field2; } } The results and error... Brother = frato Brotherhood = frateco Brotherly = frata PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 PHP Notice: Undefined offset: 1 in /home/asdf/Dev/Projects/eo_translate/script_part2.php on line 50 Line 50 = list($field1, $field2) = preg_split('/=/', $line);
  11. Hi, Is there a way to supply multiple arguments to explode()? I tried: $form_submission = "asdf. ,asdf!? asdf"; $splitSubmission = explode((" ", ".", ",", "!", "?") $form_submission); ...but get a parse error. Thanks in advance.
  12. Hi, I've been googling for a while now for an example of how to read, edit and write a configuration file. This part was easy to find... <?php $icon_settings = parse_ini_file("test.desktop"); print_r($icon_settings); ?> ...the above code works great, but how do I edit and write back a configuration file like this... #!/usr/bin/env xdg-open [Desktop Entry] Version=1.0 Name=Firefox Web Browser Comment=Browse the World Wide Web GenericName=Web Browser Exec=firefox %u Terminal=false X-MultipleArgs=false Type=Application Icon=firefox # ... and so on back to the drive? Thanks.
  13. Thanks, That worked perfectly
  14. Hi, The foreach loop below looks like it is assigning some key => value pairs to some html output. Is there a way I can assign the output to an array so I can access it by key outside the loop? Thanks...code follows... <?php include 'simple_html_dom.php'; // source: http://www.bitrepository.com/php-simple-html-dom-parser.html $url = 'http://www.amica.fi/Ravintolat/Amica-ravintolat/Ravintolat-kaupungeittain/Tampere/Technopolis-Hermia--Hermia'; $html = file_get_html($url); foreach($html->find('div[class=ContentArea]') as $key => $info) { echo $key.$info."<br><br>\n"; } ?>
×
×
  • 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.