Jump to content

.josh

Staff Alumni
  • Posts

    14,780
  • Joined

  • Last visited

  • Days Won

    43

Everything posted by .josh

  1. it's called a positive lookahead
  2. umm, my code is being done with a single regex....it's just followed by a condition based on what is matched.... Anyways... I guess positive lookaheads is a clever way to do it without a followup condition. That pattern will look for at least 1 of each. If you want to do at least 2 of each: return preg_match('~^(?=.*[^a-zA-Z](?=.*[^a-zA-Z]))(?=.*[a-z](?=.*[a-z]))(?=.*[A-Z](?=.*[A-Z])).{5,20}$~',$password); This also will check to make sure the password is between 5 and 20 chars long (which looks like you figured that bit out)
  3. If you are wanting something to be run every X seconds indefinitely, use setInterval() instead of setTimeout(). They are practically the same thing but with setInterval() you don't have to take the extra step of having your function recursively call itself. In and of itself it doesn't matter how many seconds you delay it. What matters is what you are actually doing when the function is run. For instance, if you are appending a new element to a global or static array, adding new content to page, etc... each iteration, things are going to add up. Iterating every 1s will give you 60 new elements in 1 minute, vs. 6 new elements, if you are iterating every 10s.
  4. I really frakking hate it when forms require stuff like this. Put a warning up and let ME decide how "strong" my password should be. Anyways... another thing you forgot to consider is that someone can have for instance "1AaBb2" and that should be fine....(notice how 2xwhatever is NOT together) but your regex requires them to be together. function validatePassword($password) { preg_match_all('~([a-z])|([A-Z])|([^a-zA-Z])~',$password,$matches); if ( (count(array_filter($matches[1]))>1) && (count(array_filter($matches[2]))>1) && (count(array_filter($matches[3]))>1) ) return true; return false; } // end validatePassword
  5. That is exactly what mod_rewrite does. Whenever a request is made to your server, regardless of whether a user clicks on a link, submits a form (action="..."), enters url in address bar, clicks a bookmark, etc... it will redirect to specified url. You said this was your before: news/search/?seach=value after: news/search/value ...and that's what my regex does.... But now it looks like you are trying to do: before: /news/search/?query=test123 after: /news/search/query/test123 is that what you are trying to do? If so, then it should be: $pattern = "~news/search/\?([^=]+)=(.*)~"; ...but again, I really think you should be using mod_rewrite.
  6. /* function based on the following rules: 1) username can have 0 or 1 of !@#$%^&*() but it must be preceded by a ` 2) username can have 0 or 1 number in it, but it must be preceded by a ` 3) username can have 0 or more letters, case insensitive returns true if valid, false if not */ function validateUsername($username) { // check to see if $username only contains valid chars if(!preg_match('~^[a-z0-9!@#$%^&*()`]+$~i',$username)) return false; // check if more than one number or symbol preg_match_all('~([0-9])|([!@#$%^&*()])~',$username,$matches); if ((count(array_filter($matches[1]))>1)||(count(array_filter($matches[2]))>1)) return false; // check if ` precedes symbol or number if ($matches[1]||$matches[2]) if(!preg_match('~`[0-9!@#$%^&*()]~',$username)) return false; // valide username return true; } // end validateUsername
  7. fyi you don't need that {1}
  8. soo...revised rules: 1) username can have 0 or 1 of !@#$%^&*() but it must be preceded by a ` 2) username can have 0 or 1 number in it, but it must be preceded by a ` 3) username can have 0 or more letters, case insensitive
  9. Example: $specials = array( "Sunday" =>"52in Flat Screen TV:425.00", "Monday" =>"Amplifier:145.00", "Tuesday" =>"HP Computer:355.00", "Wednesday" =>"500GB External Harddrive:99.00", "Thursday" =>"Internal Speakers:55.00", "Friday" =>"Ergonomic Keyboard:85.00", "Saturday" =>"Wacom Tablet:175.00", ); foreach ($specials as $day => $special) { list($product, $price) = explode(':',$special); // variables // $day : Sunday, etc... // $product : 52in Flat Screen TV, etc.. // $price : 425.00, etc... // example echo $day . "<br/>"; echo $product . "<br/>"; echo $price . "<br/>"; echo "---<br/>"; } // end foreach $specials output: Sunday 52in Flat Screen TV 425.00 --- Monday Amplifier 145.00 --- Tuesday HP Computer 355.00 --- Wednesday 500GB External Harddrive 99.00 --- Thursday Internal Speakers 55.00 --- Friday Ergonomic Keyboard 85.00 --- Saturday Wacom Tablet 175.00 ---
  10. umm...what?
  11. okay so let me get this straight: 1) The string should always start with ` 2) After the ` the string can contain 1 or more (is there a limit?) of any letter, number or the following symbols: !@#$%^&*() 3) No spaces anywhere (which this is technically defined by its absence in #2)
  12. 2nd thing I see wrong is elseif ($player!=$sel_result) Problem is that $sel_result is a result source. You need to actually check if a row was returned or not, pull the queried data out of the result source. Something like $sel_result=mysql_query($sel,$conn); $r = mysql_result($sel_result, 0); and then use $r in your condition
  13. first thing I see wrong is that you are using $PLAYER in you $sel query but I see only $player (lowercased)
  14. 1) Store the data in a flatfile or database 2) retrieve the data from a flatfile or database Whether you choose database or flatfile, you can make a "config" type script that will load up variables and you can include that script in other scripts with include or require
  15. That reminds me of the time my car was acting weird so I called up the mechanic and asked him what was wrong with my car and he said "Well what is it doing?" and I said "Well it's acting weird.." and he said... "Are you a fucking idiot? How am I supposed to know what is wrong with your car when instead of bringing it in for me to look at it, you call me up on the phone, and when I ask you what's wrong with it, you seem to think that "It's acting weird" will totally help me identify the problem! Seriously, if you want me to fix your car, bring it in so I can take a look at it. Or at least describe what you think is wrong, what you expect and what it is not doing (or doing) instead." True story And the moral of the story is, you may not know how to fix your code, but you should know what it is supposed to be doing and what it is (or is not) doing instead, and I can't help you unless you tell me these things.
  16. ...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it). Or...someone is trying to build their own framework. That's it! IMO there has been no other reason worthy enough to warrant not using jQuery or the like! "It will bloat my website, increase page load time, blahblah" is not a good enough reason! These frameworks are compacted and browsers will cache them! So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?" Seriously. It is super easy. Way easier than that code you're trying to post. Save yourself the headache. Get jQuery or similar. DO IT.
  17. and to compact it even more (and solve your problem), you can dynamically build that .js file with server-side scripting. You'd have your .js files in a dir and have your script tag point to a single blah.js and mod_rewrite that to point to blah.php and and in blah.php you would file_get_contents the necessary ones and compact it and output the single custom file.
  18. seriously, do yourself a favor and get jQuery or prototype framework or something.
  19. so what's your question?
  20. $routing = array('~news/search/[^=]+=(.*)~' => 'news/search/$1'); That's just an educated guess, based on what you provided. If it doesn't work, then you need to provide more info. Explain where/how you are getting the URL, the context it coming from, example context, etc... But it looks like (and based on your mention of making a CMS) what you want to do is if user goes to .../news/search/?search=blah you want to redirect to ../news/search/blah well if that is the case, then mod_rewrite is what you should be doing.
  21. a case will not get executed unless the condition is true, so if case "Two" is true, case "One" will never execute and therefore that assignment to $price will never exist. Maybe you are unsure about how switch() works? It is basically the same as doing this: if ($someValue == 'One') { $price = 1; } else if ($someValue == 'Two') { $total = $price + 2; } Why not just do $price = 1; instead of $price = 0.00; up there before the switch?
  22. $content = 'content to match'; preg_match('~class="future"[^(]+\((\d+)~',$content,$value); $value = $value[1];
  23. You need to a) save the image instead of output and then point to it like any other image (in an <img .../> tag) b) seeing as how option "a" isn't all that great, an alternative is to make the image generation script a completely separate script all by itself. You would then output your image tag in your script as you normally output an image tag, except point to the image script like so: <img src='image.php?url=urlhere&shrink=260' ... /> Then in script.php is where you have that function and the only thing it will do is the arguments from $_GET['url'] and $_GET['shrink'] and then output the image.
  24. Well they are but...you can't just call a function like that....if you really want to do it like that then you would have to eval it, but that's not really a good idea. Instead, you should setup a condition to output based on type of image. $ext = strtolower(pathinfo($Url, PATHINFO_EXTENSION)); switch($ext) { case 'jpg' : case 'jpeg' : imagejpeg($tn); break; case 'png' : imagepng($tn); break; case 'gif' : imagegif($tn); break; case 'bmp' : imagewbmp($tn); break; }
  25. mb_ereg basically that code says: if the value of $field contains "phone" or "fax" then... ...if the value of $value does NOT have between 7 and 20 of only these characters: 0-9)(xX - .... then add that error message to the $errors array
×
×
  • 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.