Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. The code snippets posted by jimmyt1988 can hardly be considered the cleanest way to do things, nor "best practices". I'd love to go into depth on one or more subjects that the OP might like to know more about, but can see the dangers already (from posts above) that he might very well take what is said as "gospel" and not take the time to learn the subject.
  2. So you're not having any particular problems, and you're not trying to be cool. What do you want?
  3. Just bear in mind that a) clean, b) secure, c) easy to read, and d) powerful might not play well together. Are you having any particular problems with any of those topics or have you just heard that your code should have those attributes and you want to fit in and be cool?
  4. I have to agree with Pikachu. Also, whole projects tend to take a very, very long time to complete (if at all) and there is, lets be honest, precious little incentive to commit time and code. Anyone can whip up a good article in a matter of hours (note: I didn't say tutorial, and I did say hours) which will be immediately, and hopefully for a long time, useful to many more folks than yet-another-cms script. Bonus points for coming forward with your thoughts though!
  5. First, a few questions... a) how would you do this without limiting profiles? Do that, then ask us how to limit. b) why is this in the regex forum?
  6. Forgive the concise answer but it is, no. The things that you ask for are predominantly outside of your control.
  7. It looks for anything enclosed in double-curly-braces (e.g. {{foobar}}) and replaces that with the value in the associated variable (e.g. $foobar). It's a very, very awful and crude token-replacement system.
  8. A key point. Lets see if the OP gives any feedback.
  9. You could also use substr_count() for seeing how many times this-word appears, if there is no need for a regular expression like above. If the log file is big, then it might be better to move through the file a piece at a time and tally up the number of occurences of the word.
  10. In case Jay's answer wasn't clear, or you didn't think to wonder why it works, please take a read of the strings documentation for info about the different styles.
  11. No problemo, I'm happy to help folks who show willing to learn.
  12. So 0002 is OK? (These Qs might seem silly, but are important)
  13. Well if your code now works, that's the important thing. As for what is unnecessary, there are a few minor things and it could be made much simpler (but that would require a complete rewrite). A quick zoom over your script gives: <h1>Our Journals</h1> <p>QOCS members received elevyn (11) 16 page publications a year, with news & events from the past to present, including stories and images from members and fleet change information within the industry.</p> <p>Below are some of our past journal covers. <em>Please note that most of the journals are printed in black & white to save money so we can pool the funds towards restoring our fleet.</em> </p> <p> <?php $dir = "journals"; $text = "journals.txt"; // Read text file containing titles into an array // of file path and title pairs $titles = array(); if ($fh = fopen($text, "r")) { while(($line = fgets($fh)) !== FALSE) { list($file, $title) = explode("|", $line, 2); $titles[$file] = $title; } } // Get list of JPG images and sort in descending order $files = glob($dir . '/*.jpg'); rsort($files); // Loop over images and display HTML $template = '<a href="%s" rel="lightbox" alt="%s"><img src="gallery-thumbs.php?file=%s"></a> '; foreach ($files as $key => $file) { $title = ''; if (array_key_exists($file, $titles)) { $title = $titles[$file]; } // Print out the template, substituting the file name and title as appropriate printf($template, $file, $title, urlencode($file)); } ?> </p> The differences that you see (like reading from the text file, using glob, using printf, etc.) don't fundamentally change how the script works, they are just different (I'd say better) ways of doing the same thing. Hopefully it will introduce you to some new things too, or just plain confuse you.
  14. Why are you sorting within the foreach loop? Your code is telling PHP to sort a single filename, which makes no sense to it nor me. You want something like: $files = ListFiles($dir); rsort($files); foreach ($files as $key => $file) { For what it's worth, that ListFiles function is pretty ugly. You aren't being particularly forthcoming with details so it is difficult to help you out. So lets sort out those details. Give a clear picture (whether you type it or take a screenshot) of the folder/file structure that you want to work with, the important points to us being whether you must go into sub-folders or not, when and/or why that might be the case. Next, you want to sort by file name but how (if at all) does the folder which the file came from affect that sorting? Finally, would you be willing to learn new ways of grabbing a list of files (one of them is the glob() that I showed you before) which might be better suited to your needs? Please answer the questions as best you can.
  15. You would need to use a string to reference the class with its namespace $class = "namespace\of\the\\$class"; Also note that you won't be able to use the aliased name (Plugin\$class) like you want to, the full namespace path must be used (whether you like it or not ).
  16. So you want to check that the string is a number between 1000 and 9999? Do you need to use a regex?
  17. Please show the code that you are using which produces the error(s).
  18. You cannot delete your own account, and anyone with access to delete it for you will tell you that they will not delete it either. If you no longer wish to be a part of PHPFreaks, simply stop visiting.
  19. No, that doesn't many sense. What errors do you keep getting?
  20. No problemo, and don't worry about asking "noobish" questions (this wasn't one, btw). We all started at nothing.
  21. Well, here's a shortcut. The glob() function will sort by file name by default and you can specify a pattern to fetch only .jpg files. // JPG files sorted in ascending lexographical order by file name $files = glob("path/to/images/*.jpg"); // Sort descending rsort($files); // alternatively, array_reverse($files); The glob pattern could be a little more specific (it currently would match any file ending with .jpg in that folder): see http://cowburn.info/2010/04/30/glob-patterns/ for details.
  22. I know that you already found the reason in the manual but here's a little more info. Part (or all if you're not getting a "strong" ID) of the ID is based on the current time: the first 8 hexadecimal digits are seconds since the UNIX epoch and the next 5 are milliseconds. Don't confuse unique with random. Finally, go for using the more_entropy parameter with uniqid() as that does at a little randomness to the end of the ID. As for a "secure way to create a token" you could still use uniqid() but hash the value (with a salt) to get something unguessable using of of the many hashing functions available.
  23. Hi again, just a quick follow up on some messages that I sent out to folks who offer training. Training an individual might get expensive (though, that's a relative term) and it's more usual to train a team to balance out the expense, would there be other people in your company to train up as well? Ibuildings offer introduction to OOP courses and are based in London, or I could give you details of a PHP consultant who is amazing and she's cheaper than them. Other ideas: there is some OOP content in the Zend course "PHP II: Higher Structures", which is delivered as a classroom course by NTI in Leeds (see http://www.ntileeds.co.uk/) and finally, Lorna wrote a series of articles about OOP which might come in valuable: the first, of four, is at http://thinkvitamin.com/code/getting-started-with-oop-php5/
  24. Is there something more to your code that you are choosing to hide? I only ask because at the moment your function is doing nothing more than an ordinary call to range would do.
  25. The return line is in the wrong place. Also, those {}s for each case are not necessary.
×
×
  • 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.