Junitar

Members
  • Content count

    23
  • Joined

  • Last visited

Community Reputation

3 Neutral

About Junitar

  • Rank
    Newbie
  1. Works like a charm. Thank you very much!
  2. Hi, I would like to list all the items contained in a folder except for 2 or 3 specific ones. For example, let's say I've item 1, item 2, …, item 10 in /myFolder. I would like to list all the items of /myFolder but item 1, item 3 and item 4. I've come up with the following code which does the work but looks a bit awkward. <?php $dir = '/myFolder'; $filesDir = new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS); $fileName = ''; foreach ($filesDir as $file) { $fileName = $file->getBasename(); if ($fileName != 'item1' && $fileName != 'item3' && $fileName != 'item4') { echo $fileName.'<br>'; } } Is there a simple and more elegant way to accomplish this? Any help would be appreciated, thanks!
  3. Thanks for the clarification! Everything's clear.
  4. Thank you very much Ingolme for your example, I understand it now! Yes, I guess it's a good enough reason. Sorry if my question was dumb but I wanted to understand why it was a bad thing not to initialize variables first. I started learning PHP 2 days ago and I don't have enough experience in programming to know it could cause a program to crash. I got it now anyway, thanks.
  5. Thank you to you both for your thorough feedbacks. I'm afraid it's still a bit fuzzy in my mind right now and the fact my English is limited sure doesn't help. I understand that a variable is used to store a content and it doesn't make sense to call a variable that doesn't exist. But in my example, I declared my variables later in the code: … $errors['name'] = 'alert'; … $name = sanitize_input($_POST['name']); … $email = sanitize_input($_POST['email']); … this is why I don't completely understand the need of specifying at the beginning that $errors = [], $name = '', $email = '', etc. If I write: <?php $test['letter1'] = 'a'; $test['letter2'] = 'b'; print_r($test); // the output is Array ( [letter1] => a [letter2] => b ) my array is well declared and ready to be used without being initialized using $test = []. I guess the answer to my question is somewhere in and
  6. Hello, I've just read the tutorial on how to process a form in PHP, available on this site, and I was wondering if there's a specific reason to declare empty variables (or arrays) at the beginning? I don't understand what is the point of doing so. For example, in the following code, why would the 2sd and 3rd lines be necessary? <?php $errors = []; $name = $email = $message = ''; if (condition) { $errors['name'] = 'alert'; } else { $name = sanitize_input($_POST['name']); if (new_condition, $name) { $errors['name'] = 'new alert'; } }
  7. Thank you to confirm my thoughts. I had a doubt after I stumbled upon an old thread on stackoverflow where a guy implied this kind of code was possibly flawed.
  8. Hi, I'm new to PHP and I was wondering if it's perfectly safe to use $_SERVER['PHP_SELF'] like so: <body<?php if(basename($_SERVER['PHP_SELF']) == 'home.php') echo ' class="home"'; ?>> … </body> As far as I understand, the $_SERVER['PHP_SELF'] variable can only be exploited when used as a link or in a form/inputs, where the variable should be wrapped into htmlspecialchars() to counter XSS attacks, am I right?
  9. Hi, I'm making a responsive centered tiled gallery for my website. For aesthetic reasons, I only need to have a margin between the images. To do so, I set a left margin to each elements but the first, in each row, using the :nth-child() selector. I got it to work as I wanted to but I'm now facing a problem with the image captions which break the floating elements if I enter too many words in them. Please, see the jsfiddle example here: https://jsfiddle.net/0w379712/ How can I do to prevent this? Ideally, I would like to have the entire row going down if there's too much text above. I thought a clear: left in the last-child of the row would fix this but it's not working. Also, would you recommend to use the :nth-child() or :nth-of-type() selector to achieve this? I've analysed several web galleries with similar mosaic and none of them used these kind of selectors. Probably for browser compatibility reasons, but can't say for sure. Edit: I finally managed to fix the problem using .tile:nth-child(2n+1) / .tile:nth-child(3n+1) { clear: left }, I messed up with the syntax of the selector in my previous attempts…
  10. I've just tested again your suggestion and it works indeed. Don't know exactly what I previously did. I guess my brain just needs some rest right now, I've done too many exercices today, it's a big mess in my mind
  11. Thanks for the help, I've already tried btn.attr("title", currentText == "menu" ? "close menu" : "menu"); but it didn't work properly (the title changed to "close menu" when it should be "menu" and vice versa). Anyway, I've just found what I was doing wrong… btn.attr("title", btn.attr("title") == "menu" ? "close" : "menu"); is now working fine but I formerly called my button title "Menu" with a capitalized "m", while I used a small "m" in the btn.attr() which screwed it all.
  12. Hi, I'm training myself at jQuery doing some exercices. I've written the following code: <button id="btn" title="menu">menu</button> jQuery(function($){ $("#btn").click(function(){ var btn = $(this); var currentText = btn.text(); // alert(currentText); if (currentText == "menu") { btn.text("close"); btn.attr("title","close menu"); } else { btn.text("menu"); btn.attr("title","menu"); } }); }); and I would like to simplify it as much as possible, using if else statement shorthand. I've managed to get it works for the .text() method btn.text(currentText == "menu" ? "close" : "menu"); but not for the .attr(). I've tried btn.attr("title", "menu" == "menu" ? "close" : "menu"); and btn.attr("title", btn.attr("title") == "menu" ? "close" : "menu"); among many other things but I can't figure out how to make it works. Any help?
  13. Thank you to you both for your input, I really appreciate your help. I will follow your advices and don't bother with old versions of IE then.
  14. If I'm not mistaken, the oninput event is supported on IE6 so I guess I will go for the jQuery method this time. I assume I'm trying to do too much but as long as I can I would like to write a code that's compatible with as many browsers as possible. It's probably unnecessary (and I guess it's a beginner's mistake) considering that I'm just making a simple photography website that will go unnoticed for most users… Thanks again for your help!
  15. Thank you very much for the fast reply. Managed to get it work perfectly with your code, just had to switch the show and hide method… I primarily used the 2 .stop() to stop an animation but I forgot to remove them. I wanted to use jQuery to prevent compatibility issues with old versions of IE. Since I don't plan to add a label outside the inputs, I wanted to be sure to have something that indicates what each input is for. I thought it was the best method but maybe I'm wrong. What do you think? I'm learning everything on my own so I wouldn't be surprised if I'm doing it wrong.