Untitled


SUBMITTED BY: Guest

DATE: Dec. 26, 2013, 6:23 a.m.

FORMAT: Text only

SIZE: 985 Bytes

HITS: 809

  1. ## Useful PHP functions
  2. highlight_string()
  3. When displaying PHP code on a website, the highlight_string() function can be really helpful: It outputs or returns a syntax highlighted version of the given PHP code using the colors defined in the built-in syntax highlighter
  4. Usage:
  5. <?php
  6. highlight_string('<?php phpinfo(); ?>');
  7. ?>
  8. str_word_count()
  9. This handy function takes a string as a parameter and return the count of words, as shown in the example below.
  10. Usage:
  11. ?php
  12. $str = "How many words do I have?";
  13. echo str_word_count($str); //Outputs 5
  14. ?>
  15. levenshtein()
  16. Ever find the need to determine how different (or similar) two words are? Then levenshtein() is just the function you need. This function can be super useful to track user submitted typos.
  17. Usage:
  18. <?php
  19. $str1 = "carrot";
  20. $str2 = "carrrott";
  21. echo levenshtein($str1, $str2); //Outputs 2
  22. ?>

comments powered by Disqus