Jump to content

salathe

Staff Alumni
  • Posts

    1,832
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by salathe

  1. The modification, I believe, has yet to be re-added since the forum software upgrade. In the mean time, folks will just have to be old school and take a look at the posts to see if a thread has been solved.
  2. Why would fewer lines be an improvement? That said, sure: $error = FALSE; if (trim(strip_tags($_POST['cap'])) != $_SESSION['captcha']) { $error = "CAPTCHA invalid"; } elseif ( ! preg_match("/http:\/\//",$_POST['link'])) { $error = "Link invalid"; } elseif (( $name == "") || ( $link == "") || ( $cap == "")) { $error = "Form not finished"; } elseif (strlen($name) > 25){ $error = "Name too long"; } elseif (strlen($link) > 100){ $error = "Link too long"; } elseif (strlen($cap) > { $error = "CAPTCHA too long"; } if ($error) { die("$error</div></body></html>"); }
  3. Wouldn't you want name instead of name1?
  4. Backslash is a special character in PHP strings, see http://php.net/types.string#language.types.string.syntax.single In your case, you would need: $new = str_replace('\\', '', $original); echo $new;
  5. You don't need that second line.
  6. I did the same, only with slightly less (8px) padding and a number of other tweaks (like removing the header entirely). It was difficult to scan the thread list otherwise.
  7. You could use one of the Ctype[1] functions (ctype_digit), a Filter[2], is_numeric[3] to name a few different approaches. 1. http://php.net/ctype 2. http://php.net/filter and http://php.net/filter.filters.validate 3. http://php.net/is_numeric
  8. Or, to save a temporary variable, pathinfo($_FILES['uploadedfile']['name'], PATHINFO_EXTENSION) See http://php.net/pathinfo for details.
  9. Looks great, thanks Daniel. [ot] Now I can go off on long, rambling tangential discussions without fear of the OP thinking all of this stuff is directly relevant to their individual post! Yay. [/ot]
  10. Awesome, thanks in advance.
  11. Any update on something like this? I know I've been not making (useful but) off-topic additions to posts recently because the off-topic comments all-too-often get mistaken for something more relevant to the topic than it might perhaps be. If we could make OT comments visually separated from the main discussion, that would be awesome. E.g.
  12. And there's no reason why you need to stop them anyway. If you think there is, you're missing the point.
  13. Since we're playing with SimpleXML, things aren't quite so simple (oh the irony). You'll have to pull out the products to an array, then sort that array on price (probably using usort as cags mentioned). You say that you've already tried to "convert to an array", that's a good starting point.
  14. There is a slight chance that the number generated by abazoskib will be 1000000 (i.e., 7 digits), to only ever get 6-digit numbers you'll need to call rand(100000, 999999).
  15. Also bear in mind that your pattern will allow anything (or nothing) before and after the date. As it stands, the value abc 2009-11-20 def will match (and your script will echo ok). For more info on what to do, take a peek at http://php.net/regexp.reference.circudollar and http://www.regular-expressions.info/anchors.html
  16. Can you do var_dump($test); ? If your code is the same as in the post above, its value will be 1997 and not the date that you think it is.
  17. That won't do the same thing, it only unsets the CNAME item (if there is one). You could do (with a named or anonymous function, whichever suits): function filter_no_cname($item) { return $item['type'] !== 'CNAME'; } $filtered = array_filter($array, 'filter_no_cname');
  18. Please be mindful when using rajivgonsalves's code, it may allow "pages" that you really don't want it to allow. For example, if the presented code was in index.php and the user requested index.php?p=index then the page would try to include itself again and again and again and again and again and again until the max. function nesting level is reached (~100). It also allows the accessing of any readable file on your server like /etc/passwd and if allow_url_include is On then someone could execute their PHP code within your script! If you are going to go with this approach, make sure to only allow accessing files in a specific directory (and sub-directories if you really need them) and be absolutely sure that the only files people can access are those that you want them to be able to.
  19. Why not just call preg_match_all() with a pattern that looks for something-that-looks-like-an-email ? I think your approach above is trying too hard to be complicated.
  20. *salathe rescues a scorched T-shirt from the fire pit
  21. Looking through lots and lots of string combinations will take a "huge time" to process, a lot of function calls are happening: for the example string above substr_count and substr will both be called 1134 times. A regex approach might be worth considering but might end up being a nightmare.
  22. If you're using PHP 5.3 look into date_diff (or DateTime::diff). If not, the user comments for that function might help.
  23. I feel so used. However, you'll have fun explaining things to whoever marks your homework. Don't forget to tell your teacher/tutor/professor how helpful and nice PHPFreaks people were.
  24. Here's one way, the process is to basically loop over the different sizes of character-combinations (from 2 to half of the subject string [you can't repeat more than half of the string without overlapping!]) and for each of those sizes loop over the different character-combinations of that length within the string. We can count the number of non-overlapping times that a chunk of the strings repeats (e.g. "kds" appears 8 times) with substr_count(). $subject = 'shdjssueeekdssdeewsdwkdskdskdsskadkdssdsadkdssadkds29skds'; $min_num = 8; $all_len = strlen($subject); // For each chunk length from 2 to half-of-string-length for ($i = 2, $max_len = floor($all_len / 2); $i <= $max_len; $i++) { // For each available offset in the subject string for ($offset = 0, $max_offset = $all_len - $i; $offset < $max_offset; $offset++) { // Get the chunk and count how often it occurs in the subject $chunk = substr($subject, $offset, $i); $count = substr_count($subject, $chunk); // Only record this chunk if it occurs at least $min_num times if ($count >= $min_num) { $repeats[$chunk] = $count; } } } // Sort values in decreasing order arsort($repeats); var_dump($repeats); /* array(3) { ["ds"]=> int(9) ["kds"]=> int( ["kd"]=> int( } */
  25. What exactly are you having trouble with? Do you understand what a "regex" is; what "validation" is; what an "email address" is?
×
×
  • 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.