[ create a new paste ] login | about

Link: http://codepad.org/43yy2pgd    [ raw code | output | fork ]

MajidF - PHP, pasted on May 17:
<?php

// in real code we'd read from a file
// $lines = file('./cookie.txt');

/**
 * we assume this is in our file
 **/
$f = "
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
 
.google.com	TRUE	/	FALSE	1305843382	cookiename	the value
.yahoo.com	TRUE	/	FALSE	1305843382	another_cookie	it's value

";

$lines = explode(PHP_EOL, $f);
$trows = '';
// iterate over lines
foreach($lines as $line) {
  
  // we only care for non-comment, non-blank lines
  if($line[0] != '#' && substr_count($line, "\t") == 6) {
    // get tokens in an array
    $tokens = explode("\t", $line);

    // let's convert the expiration to something readable
    $tokens[4] = date('Y-m-d h:i:s', $tokens[4]);

    // we can do different things with the tokens, here we build a table row
    $trows .= '<tr><td>' . implode('</td><td>', $tokens) . '</td></tr>' . PHP_EOL;

  }

}

// complete table and send output
echo "
<table>
<tbody>
$trows</tbody>
</table>";

?>


Output:
1
2
3
4
5
6
7
8
9

<table>
<tbody>
<tr><td>.google.com</td><td>TRUE</td><td>/</td><td>FALSE</td><td>2011-05-19 10:16:22</td><td>cookiename</td><td>the value
</td></tr>
<tr><td>.yahoo.com</td><td>TRUE</td><td>/</td><td>FALSE</td><td>2011-05-19 10:16:22</td><td>another_cookie</td><td>it's value
</td></tr>
</tbody>
</table>


Create a new paste based on this one


Comments: