Jump to content

Orio

Staff Alumni
  • Posts

    2,491
  • Joined

  • Last visited

    Never

Everything posted by Orio

  1. I am sure that there are better ways doing that, but here's what I've come up with: <?php $data = <<<DATA <schedule> <employee name="Joe Smith"> <day date="10/13/2008"> <shift><descr>Sweeping</descr><starttime>7:45 AM</starttime><endtime>12:15 PM</endtime></shift> <shift><descr>Yodeling</descr><starttime>1:15 PM</starttime><endtime>6:00 PM</endtime></shift> </day> <day date="10/14/2008"> <shift><descr>Mopping</descr><starttime>7:45 AM</starttime><endtime>11:15 AM</endtime></shift> </day> </employee> <consultant name="Butternut McClintock"> <day date="10/13/2008"> <shift><descr>Cliff Diving</descr><starttime>7:45 AM</starttime><endtime>12:15 PM</endtime></shift> </day> <day date="10/14/2008"> <shift><descr>Chewing Food</descr><starttime>7:45 AM</starttime><endtime>11:15 AM</endtime></shift> <shift><descr>Crackin' Wise</descr><starttime>1:15 PM</starttime><endtime>6:00 PM</endtime></shift> </day> </employee> </schedule> DATA; $regex = '#<day date="([^"]+)">(.*?)<starttime>([^>]+)</starttime><endtime>([^>]+)</endtime>.*?</day>#ise'; $replacement = "trim('$2').'<starttime>$1 $3</starttime><endtime>$1 $4</endtime>'"; $data = preg_replace($regex, $replacement, $data); ?> Orio.
  2. Orio

    Akinator

    Anyone seen Akinator yet? Just think of someone, anyone. Could be someone known from your country, internationally famous, some character from a tv series (or even a cartoon/comics whatever). You could even think about your dad, your cat or your mayor. Doesn't matter. Doesn't have to be really famous. Just make sure you choose someone you know enoguh about. Hit play, enter your name, and answer a few questions. See for yourself what happens. The only info he has about you (except your name) is your country (by your IP). Cool stuff. Orio.
  3. Try it this way: <?php //this array is built with query result $fileList2= array('1'=>'contact.html','2'=>'index.php','3'=>'re.txt','4'=>'korean_test.pdf'); // after form is submitted: if(isset($_POST['submit'])) { //prepare list of items to zip $fileList = array(); foreach($fileList2 as $value=>$name){ if(isset($_POST[$value])){ $fileList[]= $name; } } //if at least one item was selected zip them up and send it to the browser if (!empty($fileList)){ // create object $zip = new ZipArchive(); // open archive if ($zip->open('reports.zip', ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } $numFiles = $zip->numFiles; if($numFiles>0){ for ($x = 0; $x<$numFiles;$x++){ $file = $zip->statIndex($x); $zip->deleteIndex($x) or die("ERROR: Could not delete file"); } } $item = $fileList[0]; //echo $item.'<br>'; // add files foreach ($fileList as $f) { $zip->addFile($f) or die ("ERROR: Could not add file: $f"); } // close and save archive $zip->close(); $filename='reports.zip'; //header('Location: reports.zip'); header('Pragma: public'); header('Cache-Control: must-revalidate, post-check=0'); header('Content-type: application/download'); header('Content-type: application/zip'); header('Content-Type: application/force-download'); header('Content-Disposition: attachment; filename='.basename('reports.zip').';'); header('Content-Transfer-Encoding: binary'); //header('Content-Length: '.filesize('reports.zip').';'); @read('reports.zip'); exit; } else { echo "you must select an item"; } } echo '<form action="zip.php" method="post">'; foreach ($fileList2 as $value=>$name){ echo "<p><input type=\"checkbox\" name=\"{$value}\" >{$name}</p>"; } echo "<input type=\"submit\" name=\"submit\" value=\"Download\"></form>"; echo "<br>Please select the reports you would like to download"; ?> The thing is, if you are force downloading something you can't have any other output but the readfile's output. Otherwise, that data (you echoed) will be added to the zip file. I've changed a bit the structure of your main if clause. Also removed the echo you have in the middle of the script (I've commented it). Should be working now. Orio.
  4. I don't really get what replacement you are looking for. Can you give a small example of the input and the expected output you want? Orio.
  5. Can you define exactly what "unweird" chars are? Alphanumeric? What about punctuations and spaces etc'? Orio.
  6. What are you talking about? What are you trying to do? Try explaining what the problem is, what do you want to happen, what have you tried so far etc'. Orio.
  7. Are you sure you are getting results from your query? Maybe the query returned 0 rows and there's no data to add... Check it out- use print_r($row) and print_r($rowPickup) after your mysql_fetch_array()'s. See if there's data in there and if there is what does it hold. Orio.
  8. Try adding brackets around the mathematical expression: echo ($rowPickup['price'] + $row['full_price']); Orio.
  9. What the author is talking about is forms that have multiple pages. Say on the first page they select a product, and on the second they enter their name. Then a third page adds the information to a database/emails the customer etc'. So there's a need to pass the data from the first form to the last (third) page, the form processor. The $_POST array only holds the information from the last form submission, so you need to pass somehow the data from the first form. This is done using hidden fields or using sessions, in most of the cases (you could use a database for that too). So if this is your first form: page1.php <form action="page2.php" method="post"> <select name="selected_product_id"> <option value="121">Product 121</option> <option value="122">Product 122</option> </select> <input type="submit" name="button" value="Select Product"> </form> This will take the user to page2. page2 will ask for the user's name and after that take him to page3 that will process the form. But you also need to pass the data from page1 to page3, so a hidden field is added: page2.php <form action="page3.php" method="post"> <input type="text" name="username"> <input type="hidden" name="selected_product_id" value="<?php echo $_POST['selected_product_id']; ?>"> <input type="submit" name="button" value="Go!"> </form> Now page3 will receive both the username (in $_POST['username']) and the selected product (in $_POST['selected_product_id']). I hope this sheds some light. Orio.
  10. It was never something specific I wanted to do, I just once tried to find out if that was possible, and I never found a solution. I'm just stubborn Orio.
  11. But if, let's say, I don't care what the response is.. Say I only want to send data, it should be possible, right? Orio.
  12. tbh, I once also looked for a solution to the same problem, but I came up with nothing. Would be happy to hear an answer here. Orio.
  13. First, there's no such function as read(). Should be readfile() I guess. Now, the reports.zip file is in the same folder as test.php? I can't think of a reason it'd give the previous error. How exactly can it show the HTML file? Are you sure you've showed the full script? Orio.
  14. You don't need loops: <?php $day = intval($_POST['day']); if($day >= 0 && $day <= 30) $displayday = $day + 1; ?> Orio.
  15. Use the manual, it's the best resource. foreach() Orio.
  16. Let's say they were in the array $numbers: <?php $counter = 0; foreach($numbers as $str) if(strpos($str, "192.") !== 0) $counter++; echo $counter; ?> Orio.
  17. You can save the PDF data in a database and when someone accesses "show_file.php?filename=abc.pdf" show it's contents only if they are authorized. This can be done in a much nicer way using mod rewrite but you said no htaccesses... Orio.
  18. I still don't get what source of strings you're talking about. Anyway, can't you get it done from here? Orio.
  19. Can't understand what's "add it to a total", but here's the syntax you're looking for: <?php if(strpos($str, "192.") === 0) { //It starts with "192." } ?> Orio.
  20. I've downloaded a file, opened it with notepad and got: <br /> <b>Warning</b>: filesize() [<a href='function.filesize'>function.filesize</a>]: stat failed for reports.zip in <b>/home/cristina/www/www/downloads/test.php</b> on line <b>10</b><br /> <br /> <b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/cristina/www/www/downloads/test.php:10) in <b>/home/cristina/www/www/downloads/test.php</b> on line <b>10</b><br /> Line 10 and it's area has nothing to do with filesize(). Can you show the full script? Orio.
  21. Make sure there are no extra spaces/newlines outside of the php tags. The opening "<?php" should come at the first line. Also, add an "exit;" statement after readfile(). That should do it. Orio.
  22. <?php $result = sum_even($even_m); //Should be: $result = sum_even($even_max); ?> Orio.
  23. Try using: <?php preg_replace("#(".preg_quote($trimmed,'#').")#i", "<span class=\"searchresults\">$1</span>", $EntryID); ?> Orio.
  24. <?php if(!preg_match("/#?[0-9A-F]{6}/i", $str)) //With or without # echo "Invalid! must 6 valid hex digits!"; ?> Orio.
  25. You'll need to look into AJAX. Your client side script (JS) will count the x seconds, and then send behind the scenes a request to your server. The server will check if there are new records, and return the result (true/false) back to the client side script. From there the script could decide whether to reload the page or not. The whole "behind the scenes" part is done using AJAX. Orio.
×
×
  • 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.