Jump to content

j.smith1981

Members
  • Posts

    333
  • Joined

  • Last visited

    Never

Everything posted by j.smith1981

  1. Hi there I am having a problem outputting file names in PHP using readdir() function. The problem is with this code below: <?php if(is_dir($directory)) { if($dh = opendir($directory)) { while(($file = readdir($dh)) !== false) { echo $file; } closedir($dh); } } ?> With $directory obviously being the directory I wanted to output allowing me to let users say change the style sheets they where using, going through a book of php work you see in Hacks (meaning of course making PHP do things you didn't realise where possible or knew how to do, or a very hit and miss approach to getting work done as quickly as possible and the like), it's really expanding my capabilities in PHP. Though everytime I try and output the file names in which ever directory there's this kind of output: Where there's one leading fullstop/period (.) and then 2 trailing ones, is there any bette method that gets rid of these entirely please? Would really appreciate your help on this and thank you for your help in advance too! Jeremy.
  2. I am just interested when you see something like this: <?php $myarray = array(); ?> When delcaring an empty array, this is when you don't know what data will be held inside that array right? I mean if say you where making a playlist in PHP, which is what I am working on at this very moment in time, you wanted to list all the files (MP3 files if you will) as an array so you'd have say all 25 mp3 files in a restricted directory, but you don't know yet what the file names will be. To make the loop work to fill up the array this is when you would use the tiny little snippet above yes? Sorry please correct me if I am wrong this is the whole point of this thread! Also what would happen if you did the loop but not do the above snippet before the loop? Thank you and I look forward to any replies, Jeremy.
  3. It's an absolute pleasure. Not being funny here but it's a very good theoretical thing a forum for database normalisation, when all tables relate to each other in some way. Cardinality being quite important, where the user can subscribe or sign up but not post replies yet, cardinality can either be set as on or off, I mean it's more about diagrams (can't remember the symbol that's used to represent this), but means a users login doesn't have to exist on another table it relates to (in this case posts), if the user has not made any posts yet. But they can have many posts, that's a 1 to many relationship. Probably waffled too much but that's basic normalisation really, there are deeper levels I think going to 5th the normal form but anything over 2 or 3 starts to get a little too complex (why they go up to degree level to teach this even Masters degree's exist in information management, there's allot of money to be made (not in forums) but the world of information at large). It's a good area to get into, but it's just being overly logical on how you want to understand the data and improve upon that. Anyways good luck!
  4. I think I can declare this thread closed now, but just been going through the first set of examples in that book mastering regular expressions and have to say I have probably learnt more today than I have in the 2 months I have been studying regular expressions. Actually stepping out and doing it entirely on my Linux server, mimicing the examples in the book, by creating the searchable files and then seeing how they compare etc. It all entirely makes sense, one thing is the ^ $ which seeing that/those rather in a different explanations really helped a great deal, so thank you! Got a few ideas now of what I want to do just to experiment with them but that book's a very good read, will continue on and if I have any trouble will make another post highlighting that problem I am having and question what I have done. Thank you so very much! Jeremy.
  5. I have ordered that book and am reading some of it from a site I am subscribed to, just thought I would read through it to get a head start and purchase the first book as a good one to go for. Just a question about that answer I wanted to go over in my own words to make sure I understand what this means: /^[a-z0-9][a-z0-9_-]*$/ This means start with the caret metachar yes? This then means the first char must be either a-z or 0-9, but one thing I don't mind having is upper or lowercase chars in which ever position the user wants so MyUsername or myUsername123 would work. This would then be something like: /^[a-z0-9]i[a-z0-9_-]*$/ Would this work, where i is the case insensitive metachar, also on another note actually this would mean the first char would could be either A-Z or a-z and then 0-9, I have noticed when looking at one of them why I found - worked, which again is valid, so I see exactly what I did before, which is good. How would I allow for case insensitivity in the rest of the regular expression without just limiting it to the first char, would I just put this in at the end possibly? I don't need to go any further but I understand it and will write it in my own codes comments about what it does for my own reference.
  6. Oh thank you so much for your help. Looking at your example of what I would need to do and reading has helped allot but as per usual I would have to type it out to really understand it, can think of a way of say changing it, to make it do something I anticipate but won't necessarily use to explain it further to myself as such. I mean that (not being funny), but really massively helps me understand something like one of the things I have just done, doesn't make any sense in spoken language terms but has helped me out a bit in classes like so: <?php preg_match('/gr[ael]y/', 'The shirt was grey'); preg_match('/gr[ael]y/', 'The shirt was gray'); preg_match('/gr[ael]y/', 'The shirt was grly'); This helped me make sense of a very simple class, just yea adapting theories to real situations is what I am finding really hard. But with the links in the 2nd response, I really appreciate it when someone goes out of their way to help me, really going for as much info as I can possibly get on regex's, was almost giving up with them about a month ago and the stuff I didnt really understand is making sense. Going by another example I just wanted to do out of my own interest was to make a valid say literal URL like so: <?php preg_match('/http:\/\/mysite\.co\.uk/', 'http://mysite.co.uk'); The last one taught me that each forward slash is a meta char yes? So I escape each one, one of the first mistakes I literally forgot about was the full stop meta char and then escaping that so it becomes a literal (is that the comparison term for that then?) I will look at that link and have a look at the books contents on the web, really won't be too costly if I go on amazon market place (where I tend to buy all my books from really). Thanks ever so much you 2, much appreciated! Jeremy.
  7. Sorry just to recap on one I have created myself just to show range classes in regular expressions, I just wanted to confirm I am thinking about this correctly. I am doing this one here: <?php preg_match('/[a-z]/', 'this could mean anything between a-z', $matches); print_r($matches); It of course only comes up with a lowercase t so this would be true if it was put into an if condition, but it doesn't need to check past the first occurence of the first letter of the string right? If it must then I would have to set that in right? If it was to contain anything from 0 to 9 then it would come back not allowed right? Just wanted to get my head around this a bit more, just going off the tips from that set of tutorials in my above post.
  8. I have been dabbling with regular expressions again with PHP. Just finding these examples I am running from on: http://www.regular-expressions.info/charclass.html Their good tutorials but I am finding it hard getting away from them. I am having problems implementing an idea of mine and just wanted your opinions on how to get around a little problem, I mean what I wanted was a username where the user is able to register a username that must start with a-z or 0-9 but can include . and _ after the first character. So usernames like '09_myusername' would be valid but '_myusername' or '.myusername' would be invalid, does that make any sense? How would I go about doing this, does anyone have any ideas they could walk me through? Massive thanks to anyone that can help me in advance, Jeremy.
  9. I would have say just a 2 column table of 'votes' The user id and the postid of the message that user has voted for. But when the user goes to the page where that exists, if the user has already voted and their userid exists for that post in that row on the database, the link doesnt exist in the presentation of the page. Whereas on any other message if the user doesnt exist on the postid of any other then it would show the link. That logically speaking should work.
  10. I am just curious does anyone know of any really good tutorials where I can install Ruby and Ruby on Rails with Centos v5.6? It's just the default install from the Centos repos are not supported anymore with Ruby on rails, well they say they advise of a newer version of ruby. Does anyone maybe know or who have done this before with this particular distribution? I just wanted to get an idea of how to install it manually to get the latest updated version of Ruby and of course Rails on this particular distribution. Thanks and I appreciate any replies, Jeremy.
  11. MySQL I feel personally is the best of the free based server databases (if not the best). I mean the propietry ones (where you pay for a licence) are not exactly cheap, been years since I went around looking for say an Oracle Develper suite licence (when I was at University) and I found out they start over here at around £10,000 per year, but have absolutely no clue how much they are now. But with Oracle there's different levels of licencing for what you need like data-warehousing, where say Wolseley which are one of the say 5 companies in the UK with an actual solid Oracle licence (our works CMS and general work tool) is based on Oracle but through another company who hold the Oracle licence. I mean Wolseley have a huge database where all their stores sales go into one database and this department(s) download that information at a given time of the day (each day), as I have had a friend that works there on these such systems, developing database schema's for them. That's when you store all the information in one place then that keeps building up to a certain point when a department will (probably not to their knowledge of how it actually technically works) download that data and process it which ever way they see fit, or the application they use processes that information. Oracle is that expensive for that reason, it has been known that it is by far a much more integral database system, there is a free example of oracle you can install, it's based on their 10g version, but only allows you to have 1 database and there's some other limitations, can not exactly remember what they are though. Or if you go on a course at a University that does degree level information systems (yes there are degree's in databases) , you will most likely find they have an educational version of Oracle, a full licence based system where you can install it on your own computer (providing you have 10-15 Gb's of disk space, seriously its that big!) I mean one of the integral parts of Oracle is you must on every table specify a Unique ID (primary key) for every table you create or the SQL editor called SQL* Plus will reject your commands. I have personally done some entry level based work in my 2nd level at University, both in MySQL and Oracle, like one of the difference between the 2, is the following command in mySQL to drop any dependant data in InnoDB, you'd use: DROP TABLE <tablename> cascade; In oracle this is like using the command: DROP TABLE <tablename> cascade constraints; Just thought I would give a very small intro into the differences, but the overhead of Oracle is huge, that's why it costs so much for a licence for it, but it probably can hold a whole lot more data and it does that because it's used for business purposes, MySQL does cut across this but won't allow you to use any type of data warehousing capabilities for example. Infact the default user they give you just as an example is username 'scott' and the password 'tiger'. Scott was one of the first developers at Oracle and his cat was called Tiger, bit of useless information for you.
  12. No there's quite a bit more, I just thought it might be something I've done in there, here's the full script: <?php require_once 'init.php'; require_once 'header.html'; if(array_key_exists('action', $_GET)){ switch ($_GET['action']) { case 'register': require_once 'inc.database.php'; if(array_key_exists('register', $_POST)) { foreach($_POST as $v) { trim($v); } if(strlen($_POST['username']) === 0 || strlen($_POST['email']) === 0 || strlen($_POST['password']) === 0 || strlen($_POST['password2']) === 0) { $error = 'You missed out some required fields, please try again'; } else { // now make true vars out of them: $username = mysql_real_escape_string($_POST['username']); $email = mysql_real_escape_string($_POST['email']); $password = mysql_real_escape_string(sha1($_POST['password'])); $password2 = mysql_real_escape_string(sha1($_POST['password2'])); $salt = md5($username.date('U')); // make up the remaining variables: $host_ip = $_SERVER['REMOTE_ADDR']; //creates the unix time stamp (entirely based on BST if its applicable! if(date('I') === '1'){ // if you check date('I') in the php manual, this outputs if you put echo infront of it 1 or 0 (bool value). 1 = BST = 1 kind of! $time = date('U') + 3600; // plus 1 hour if BST holds true! } else { $time = date('U'); } // process the registration further: // firstly by validating the username against a set criteria using regex's: if(preg_match('/^[A-Za-z](?=[A-Za-z0-9_.]{4,31}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/', $_POST['username'])) { // i want a non regex function to do this! // if(preg_match('/^[A-Za-z](?=[A-Za-z0-9_.]$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/', $_POST['username'])) { if(strlen($_POST['username']) < 5) { $error = 'The username must be 5 characters or longer'; } else { // if the username is of alphanumeric chars of _. and a-z (uppercase allowed too), 0-9 then: $sql = "SELECT username FROM blog_users WHERE username = '$username'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { $error = 'Username is already taken, please try another'; } else { $sql = "SELECT email FROM blog_users WHERE email = '$email'"; $result = mysql_query($sql); if(mysql_num_rows($result) > 0) { $error = 'The email address you entered is already taken, please try a different email address'; } else { // now check the email address is a valid and then if the domain actually exists! if(filter_var($email, FILTER_VALIDATE_EMAIL)) { // now check if the domain exists: $split_email = split('@', $email); $host = $split_email[1]; // now use the dns checker function in php: if(checkdnsrr($host, 'ANY')) { if(strlen($password) >= 5) { if($password2 === $password) { // now process login with mysql database: $sql = "INSERT INTO blog_users (user_id, user_type, username, password, email, user_ip, register_date, last_logged_in, salt, active) VALUES (NULL, 'U', '$username', '$password', '$email', '$host_ip', $time, $time, '$salt', '0');"; $result = mysql_query($sql); if($result) { $subject = "blog.jeremysmith.me.uk Account Verification Required"; $message = "Hello testing this script for now from"; $headers = "From: no-reply@jeremysmith.me.uk\r\n". "Reply-To: no-reply@jeremysmith.me.uk\r\n". "hsmedia.co.uk Mail Service"; // send off email for verification of email address: mail($email, $subject, $message, $headers); } else { $error = 'An unexpected error occured, please try again later'; } } else { $error = 'The password you entered does not match, please try again'; } } else { $error = 'Your password is too short, must be a minimum of 5 characters long and it can contain any value you want'; } } else { $error = 'Email domain does not exist, please try again'; } } else { $error = 'The email address you entered was not valid, please try again'; } } } } } else { $error = 'You entered some illegal characters in your username please try again!'; } } } else { $message = 'Please use the form below to register on this site:'; } break; case 'login': $message = 'Please use the form below to login to this site:'; // $error = ''; break; default: // if no other actions are present send user back like below: header('location: index.php?error=1'); break; } ?> <form id="<?=$_GET['action'];?>" name="<?=$_GET['action'];?>" method="post" action="<?=$_SERVER['PHP_SELF'];?>?action=<?=$_GET['action' ];?>"> <p><?=(isset($message)) ? $message : '';?></p> <table> <tr> <td><label for="username">Username: </label></td> <td><input type="text" id="username" name="username" maxlength="25" size="27" value="" /><?=($_GET['action']==='register') ? '*':'';?></td> </tr> <?php // if register then show email: if(isset($_GET['action']) && $_GET['action'] === 'register') { ?> <tr> <td><label for="email">Email: </label></td> <td><input type="text" id="email" name="email" size="27" value="" /><?=($_GET['action']==='register') ? '*':'';?></td> </tr> <?php } ?> <tr> <td><label for="password">Password: </label></td> <td><input type="password" id="password" name="password" size="27" value="" /><?=($_GET['action']==='register') ? '*':'';?></td> </tr> <?php // if register then show email: if(isset($_GET['action']) && $_GET['action'] === 'register') { ?> <tr> <td><label for="password2">Confirm: </label></td> <td><input type="password" id="password2" name="password2" maxlength="25" size="27" value="" /></td> </tr> <?php } ?> <tr> <td colspan="2"> <input type="submit" id="<?=$_GET['action'];?>" name="<?=$_GET['action'];?>" value="<?=ucfirst($_GET['action']);?>" /> </td> </tr> </table> <p><?=(isset($error)) ? $error : '';?></p> </form> <?php require_once 'footer.html'; } else { header('location: index.php?error=1'); } Any help's appreciated again, Jez.
  13. I am having problems with this mail function implementation here: $subject = "blog.mydomain.com Account Verification Required"; $message = "Hello testing this script for now from"; $headers = "From: no-reply@mydomain.com\r\n". "Reply-To: no-reply@mydomain.com\r\n". "mydomain.com Mail Service"; // send off email for verification of email address: mail($email, $subject, $message, $headers); I just don't get why its outputting the test message in the browser window, any ideas?
  14. Oh that's wonderful! Will go back over this in a couple of hours, but I kind of get it, makes sense when you look at the logic compared to what you have just said. Will go back over some other examples and compare (how I do well with learning to be honest). Much appreciated! Jez.
  15. Ahh that's wonderful. Will have a crack with that, to see what else I can do with it, wonderful thank you so much. Really have to say this is the most impressive forum I have ever been on for PHP tips and tricks. I like the way within a few hours in the afternoon someone will reply with a good example of what to do and explaining a reason for this, if it seems quite confusing but those to me look very interesting. Love the way I am trying to go for more maintainable code, using a reference from memory of a book I have been reading on PHP and trying the examples out for myself. Thanks again, Jez.
  16. I have the below script snippet that I found on the web, I like it, does what I ask of it, however I have some questions regarding it's logic if you will. Here is the preg_match: preg_match('/^[A-Za-z](?=[A-Za-z0-9_.]{3,31}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/', $input); I know that the caret ^ is the start of the pattern that it must match, that being all alpha characters only? i.e. all the way from a to z and then in upper-case as well? ? being (I can't remember that one exactly, equaling anything from a to z and then an underscore and a dot (.) which means anywhere in the string right? (I feel I am learning allot from the previous examples of Regex's, just need some help). The next one is 3 to 31 characters in length? The $ is the end of the pattern, have I got this right? I am confused as to what the rest of the logic does, wouldn't it make more sense just to have the first bit, I know it's a question based on what I would want it to do, it's just allow say the pattern up to the character class at the start? I mean I would have to change the {3,31} and change it to any length I wish, I would say a min of 5 chars then a maximum of 35. Any help is appreciated, Jez.
  17. I am trying to trim the values of a $_POST array like so: <?php if(array_key_exists('register', $_POST)) { foreach($_POST as $value) { trim($value); } } But then seeing if I can use another loop to see if anything has actually been entered, how would I go about doing this? Keep thinking of a better way of doing this but I am not too sure how. Any help's appreciated, Jeremy.
  18. I mean sorry would I list all the symbols or say if any other tag than these (the quoted ones in my previous post) are the only allowed valid ones? How would I make the logic of a preg_match() take appreciation to this? Just going through all the logic in the world, eventually will make sense but it's just I am not getting productional really on my own basis, could you help please? I really fully appreciate the replies so far though! Thank you for reading, Jeremy.
  19. Thank you ever so much for all your replies, really truly appreciate them! I am learning so much about regex's now, thanks to your invaluable help. I mean the whole point of me coming on here is to learn about programming area's, really appreciate your replies. Will dig away around them, I mean with the unicode yes of course, but really all it was (and I think you realise this too) is that it was just entirely an example not really fussed about that for now, but will just dig into that if a case was to come up where I would need to do that and will go through the logic once again. Of how many times you can search a string etc, I do understand though that I am kind of burrowing myself into a corner with these, always thinking of how to extend such expressions. Like would it be best if I was to say only going to allow certain values into a regex, say like for a username validation, I was to just allow the following chars in them: I noticed when I tried putting in a regular expression, with literally [a-zA-Z] it allowed me to put in all kinds of characters, wanted to keep a fine control on what the user can input into them. How would I allow all those quoted symbols anywhere and as many as they like in string? Might finally get me a slight push to get used to regex's. Again really appreciate any replies, Jeremy.
  20. Whilst on the hunt for a good free regexp editor, been playing around with various regex's. It's actually sticking too! Not being able to actually do very much except for literals but it's quite good now I am understanding somewhat what their actually doing rather than just thinking yes that would work but only relying purely on the author of a post, which I can not stand to do, if I start doing that I won't use it, even though it works, does anyone else do the same as me? Anyways enough the waffle, just wanted to show one I have customised on a very simple level though: http://www.webresourcesdepot.com/learn-test-regular-expressions-with-the-regulator/ I have then changed this slightly to: preg_match('/H(á|ae?)nd(a|ae?)l/', $string, $matches); Say I put in (as a literal): 'Hándael' it would find 3 occurences of the pattern in the string wouldn't it? H is a literal? (please correct me if I am wrong the whole point of me making this post is so I can compare what I believe to be true as such). ae is in the or with the | sign in brackets right? then the final 'l' is a literal (sorry please correct me if I am using the wrong terminology for what I am explaining). Would appreciate your feedback very much, just for memory what exactly is the metachar for anywhere in the string? Just out of interest. Alright I will leave it there, thank you and I appreciate any responses in advance, Jeremy.
  21. When it says: In this link: http://www.regular-expressions.info/tutorial.html Is Notepad++ a good regex editor at all, or does it have the capacity to do so? If not is there any other free ones available I can use?
  22. Thank you for that. Will give that a read also, infact the one I posed the link I mean, was not that good. But I know I can make them work for my own usage, which is why I am experimenting and it's making sense. Just out of something completely random got something like this working: <?php $string = 777.'-'; $string .= 7777777; $pattern = '/\d\d\d/'; // could start off with going along all the way its meant to be formatted, but that would be far too long! I have managed to better this by doing the following: <?php $string = 777.'-'; $string .= 7777777; $pattern = '/\d{3}-\d{7}/'; preg_match($pattern, $string, $matches); print_r($matches); That should output: Though that is just an off the top of my head experiment.
  23. I am also looking at this aswell: http://www.codeproject.com/KB/dotnet/regextutorial.aspx But will of course give that book a look. Thank you.
×
×
  • 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.