Beginer with a PHP, Curl problem

software development

#1

I thought it would be an interesting exercise to take output from NW Avalanche Center for the White Pass snow pack and reformat it for my PDA. For some reason the output from http://www.nwac.us/products/OSOWPS has a .txt extentsion on it, so my PDA browser, Blazer 4.3, doesn’t want to display it. Instead I have to save the file and figure out some way to read the file offline.

I can read in the file with curl, but then printing it out it gets jumbled because the whitespace gets removed. Also

formats the text smaller on my desktop Firefox, but on the PDA, it’s the same size, just bold.

Am I going to have to read a list of variables of each line, then printf back the list to keep the columns lined up? Is there a better way to reduce the font size?

I blundered into the nl2br function. I had trouble using it at first until I spelled it correctly. I was using a 1 instead of l.

A working version is at http://ykfp.org/php/nwac/getwhitepass2.php

White Pass snow
<?php // Paul Huffman, 1-2-2008

//retrieve the White Pass text file from NWAC
$theurl=“http://www.nwac.us/products/OSOWPS”;

$ch = curl_init();
$timeout = 5; // set to zero for no timeout
curl_setopt ($ch, CURLOPT_URL, $theurl);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$contents = curl_exec($ch);
curl_close($ch);

// display file
//echo nl2br($contents);
//echo $contents;
// explode the content using newlines as delimeters
$aContents = explode(chr(10), $contents);

// print $contents one line at a time
//for ($i=3; i<34; $i++) {
for ($i=3; $i<count($aContents)-23; $i++) {
print “$aContents[$i]
\n”;
//print nl2br($aContents[$i]);

}

?>

This signature line intentionally blank.


#2

You can preserve the columns by wrapping the output in a

 element, and use CSS to control the font size. Example:[code]<?php
header(“Content-Type: text/html;charset=UTF-8”);
$url = “http://www.nwac.us/products/OSOWPS”;
$ch = curl_init();
$timeout = 10;
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
curl_close($ch);
?> White Pass Snow

White Pass Snow

<?php echo $data; ?>
[/code]-- [url=http://jessey.net][b]si-blog[/b][/url] -- [b]Max[/b] discount on [i]any[/i] plan with promocode [url=http://dreamhost.com/r.cgi?53419|SCJESSEYTOTAL][b]SCJESSEYTOTAL[/b][/url]

#3

Thanks, that got me unstuck. Now the columns are lined up well enough in Firefox.

But the Blazer browser is funny though. It doesn’t react to changes in <style=font-size:>. There is an option in the browser to view the content in large or small type, just two choices. And the column alignment isn’t right. It looks like the spaces are narrower than the other letters. Is there a non-proportional style tag?

This signature line intentionally blank.


#4

You can use a monospace font family by changing the “style” attribute in my example, and you may be able to force a smaller font-size by using a keyword:

<pre style="font: small 'Courier New', Courier, monospace">si-blog
Max discount on any plan with promocode SCJESSEYTOTAL


#5

I got the output looking pretty good and compact in Firefox but the Blazer browser doesn’t seem to pick up the mono style, no matter what I try. I can even see it briefly on the PDA screen with the format correct before Blazer applies its local font style to it. It looks like everything is monospaced except for the blanks, which are narrower. http://ykfp.org/php/nwac/getwhitepass5.php

The style I’m currently trying is:

<?php
....
?>

This signature line intentionally blank.


#6

Maybe your PDA is just crappy, then? The only advice I have left is that inline CSS is much more likely to override global styles set by the browser than embedded CSS (which is what you have), so try setting the monospace style directly on the

 element.

si-blog
Max discount on any plan with promocode SCJESSEYTOTAL