You are here: Re: Customizing unserialize output. « PHP Programming Language « IT news, forums, messages
Re: Customizing unserialize output.

Posted by thecoolone on 12/25/06 14:02

petersprc wrote:
> Hi,
>
> You can use the script below to do this. Pass the serialized data to
> the method printResults:
>
> --- Begin Text ---
>
> <?
>
> class YahooResultsView
> {
> function printResults($rawResponse)
> {
> $response = unserialize($rawResponse);
>
> $startHtml = $this->htmlEncode(
> $response['ResultSet']['firstResultPosition']);
> echo "<ol start=\"$startHtml\">";
>
> foreach ($response['ResultSet']['Result'] as $result) {
> $clickUrlHtml = $this->htmlEncode($result['ClickUrl']);
> $titleHtml = $this->htmlEncode($result['Title']);
> $summaryHtml = $this->htmlEncode($result['Summary']);
> $displayUrlHtml = $this->htmlEncode(
> rtrim($result['DisplayUrl'], '/'));
> $sizeHtml = $this->htmlEncode(
> $this->formatMemorySize($result['Cache']['Size']));
> $cacheUrlHtml = $this->htmlEncode($result['Cache']['Url']);
>
> echo <<<end
> <li><div><a class=title href="$clickUrlHtml">$titleHtml</a>
> </div>
> <div class=summary>$summaryHtml</div>
> <span class=url>$displayUrlHtml</span> -
> <span class=size>$sizeHtml</span> -
> <a class=cache href="$cacheUrlHtml">Cached</a>
> end;
> }
>
> echo '</ol>';
> }
>
> // Convert bytes to the best unit of measurement
>
> function formatMemorySize($bytes)
> {
> if ($bytes < 0x3E8) {
> return $bytes . 'b'; // bytes
> } elseif ($bytes < 0xF4240) {
> return round($bytes / 0x3E8) . 'k'; // kilobytes
> } elseif ($bytes < 0x3B9ACA00) {
> return round($bytes / 0xF4240) . 'M'; // megabytes
> } elseif ($bytes < 0x3B9ACA00 * 0x3E8) {
> return round($bytes / 0x3B9ACA00) . 'G'; // gigabytes
> }
> return round($bytes / 0x3B9ACA00 * 0x3E8) . 'T'; // terabytes
> }
>
> function htmlEncode($str)
> {
> return htmlentities($str, ENT_QUOTES);
> }
> }
>
> ?>
>
> <html>
> <head>
> <style>
> body {font: 83%/1.2em arial,helvetica,clean,sans-serif;}
> #results {width: 600px;}
> #results a {color: #0000de;}
> #results a:visited {color: #639}
> #results a:active {color: #f00;}
> #results li {margin: 0 0 17px 21px;}
> #results .title {font-size: 120%;}
> #results .summary {color: #000;}
> #results .url {color: #008000;}
> #results .size {color: #8284cc;}
> #results .cache {color: #8284cc;}
> </style>
> </head>
> <body>
> <div id=results>
>
> <?
>
> $view = new YahooResultsView;
> $view->printResults(file_get_contents('response.txt'));
>
> ?>
>
> </div>
> </body>
> </html>
>

thanx peter.
But can u clarify why do u have the "formatMemorySize" function ??

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация