• Like
Zendcon 2007 Features
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

Zendcon 2007 Features

  • 423 views
Published

 

Published in Business , Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
423
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
16
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1.
      • PHP Features you didn't know existed
    Elliott White III – Eli digg.com
  • 2. What is this talk?
      • Good Question
      • A random list of 'neat things' that you can do in PHP, that perhaps you didn't know about.
      • At least hopefully there are a few that you haven't heard of.
  • 3. http_build_query()
      • $vals = array('search' => 'PHP 5 in Practice',
      • 'site' => 'digg.com');
      • $query = http_build_query($vals);
      • $resend = http_build_query($_GET);
  • 4. ignore_user_abort()
      • ignore_user_abort(true);
      • $bool = connection_aborted();
  • 5. Closing Connections Early
      • ignore_user_abort(true);
      • header("Connection: close");
      • header("Content-Length: " , mb_strlen($response));
      • echo $response;
      • flush();
  • 6. register_shutdown_function()
      • function shutdown() {}
      • register_shutdown_function('shutdown');
  • 7. set_time_limit()
      • set_time_limit(600);
      • Use with register_shutdown_function to handle timeouts.
  • 8. range()
      • $array = range(10,20);
      • $reversed = range(20,10);
      • $stepped = range(10,20,3);
      • $alpha = range('a','f');
  • 9. readfile() as a passthrough
      • readfile('http://example.com/data.html');
      • file_get_contents('http://example.com/data.html');
  • 10. strip_tags()
      • $stripped = strip_tags($input);
      • $semi = strip_tags($input, '<p><b>');
  • 11. Spellchecking
      • $dict = pspell_new('en');
      • $words = str_word_count($str, 2);
      • foreach ($words as $word) {
      • if (!(pspell_check($dict, $word))) {
      • $suggest = pspell_suggest($dict, $word);
      • echo &quot;{$word}: &quot;, implode($suggest, ', '), &quot;<br />&quot;;
      • }
      • }
  • 12. Similar Text / Levenshtein
      • levenshtein() returns the number of changes needed:
      • $diff = levenshtein($name, 'Eli White');
      • similar_text() can give you a percentage of similarity:
      • $num = similar_text($name, 'Eli White', $percent);
  • 13. Soundex / Metaphone
      • $key = metaphone($word);
      • $key = soundex($word);
      • Metaphone is 'supposed' to be more accurate since it understands basic rules of English pronunciation, and generates keys of variable length.
  • 14. serialize() & unserialize()
      • $var = array('digg' => 1, 'life' => 42);
      • $v = serialize($var);
      • $var = unserialize(&quot;a:2:{s:4:&quot;digg&quot;;i:1;s:4:&quot;life&quot;;i:42;}&quot;);
  • 15. Header buffering & headers_sent()
      • Ini File:
      • output_buffering = 4096
      • if (!(headers_sent())) {
      • setcookie('what', 'It Works');
      • }
  • 16. @ symbol
      • $result = @function();
      • @$val += 1;
      • $whatever = @$_GET['v'] ? $_GET['v'] : 'default';
  • 17. @ vs. isset() vs. array_key_exists()
      • @$var['a']['b']
      • isset($var['a']['b'])
      • array_key_exists('b', $var['a'])
  • 18. trigger_error()
      • trigger_error(&quot;Whoops&quot;, E_USER_ERROR);
  • 19. Direct access of globals - $GLOBALS
      • $GLOBALS['myvar']
  • 20. fscanf() using character sets
      • fscanf($file, &quot;%3s*%40[^ ] %f &quot;, $a, $b, $c);
      • fscanf($file, &quot;%3[a-c] %6[0-9] &quot;, $a3, $a6);
      • fscanf($file, ' &quot;[^&quot;]&quot; &quot;[^&quot;]&quot; ');
  • 21. do {} while (false);
      • do {
      • if (something()) {
      • break;
      • }
      • somethingelse();
      • } while (false);
  • 22. php://input & php://stdin
      • Command line input:
      • file_get_contents('php://stdin');
      • Raw Post data:
      • file_get_contents('php://input');
  • 23. php://filter
      • file_put_contents('php://filter/write=string.toupper|string.rot13/resource=myfile.rot');
      • readfile('php://filter/read=string.strip_tags
      • /resource=http://digg.com');
      • var_dump(stream_get_filters());
  • 24. compress.zlib://
      • file_put_contents('compress.zlib://gzipfile.gz', 'DATA');
      • readfile('compress.zlib://gzipfile.gz');
  • 25. Generating lists of months/weekdays
      • foreach (range(1,12) as $month) {
      • $daystamp = mktime(0, 0, 0, $month);
      • $monthnames[] = date('F', $daystamp);
      • }
      • foreach(range(1,7) as $day) {
      • $stamp = mktime(0, 0, 0, 1, $day);
      • $days[date('N', $stamp)] = date('l', $stamp);
      • }
  • 26. Including code from other servers
      • include 'http://example.com/file.inc';
  • 27. Possible Other Topics
    • Output Buffering
    • SPL Iterators
    • Assertions
    • Exif
  • 28. Digg is Hiring!
    • Digg.com is hiring experienced PHP programmers!
    • http://digg.com/jobs
    • [email_address]
  • 29. Any Questions?
      • For this presentation and more: http://eliw.com/
    Visit http://digg.com/