note 75175 modified in function.fsockopen by danbrown

From: Date: Sun, 20 Jul 2008 19:30:29 +0000
Subject: note 75175 modified in function.fsockopen by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-142297@lists.php.net to get a copy of this message
[EDIT by danbrown AT php DOT net: The original function has been deleted from the user notes. The author of this note credits the original author.] Just a correction The function by jbr at ya-right dot com work nice for me (thanks), but is missing a last case, for when the response is not chunked (because it's too short for exemple), here a corrected function : <?php function decode_body ( $info, $str, $eol = "\r\n" ) { $tmp = $str; $add = strlen ( $eol ); $str = ''; if ( isset ( $info['transfer-encoding'] ) && $info['transfer-encoding'] == 'chunked' ) { do { $tmp = ltrim ( $tmp ); $pos = strpos ( $tmp, $eol ); $len = hexdec ( substr ( $tmp, 0, $pos ) ); if ( isset ( $info['content-encoding'] ) ) { $str .= gzinflate ( substr ( $tmp, ( $pos + $add + 10 ), $len ) ); } else { $str .= substr ( $tmp, ( $pos + $add ), $len ); } $tmp = substr ( $tmp, ( $len + $pos + $add ) ); $check = trim ( $tmp ); } while ( ! empty ( $check ) ); } else if ( isset ( $info['content-encoding'] ) ) { $str = gzinflate ( substr ( $tmp, 10 ) ); } else { $str = $tmp; } return $str; } ?> --was-- [EDIT by danbrown AT php DOT net: The original function has been deleted from the user notes. The author of this note credits the original author.] Just a correction The function decode_jbr at ya-right dot com work nice for me (thanks), but is missing a last case, for when the response is not chunked (because it's too short for exemple), here a corrected function : <?php function decode_body ( $info, $str, $eol = "\r\n" ) { $tmp = $str; $add = strlen ( $eol ); $str = ''; if ( isset ( $info['transfer-encoding'] ) && $info['transfer-encoding'] == 'chunked' ) { do { $tmp = ltrim ( $tmp ); $pos = strpos ( $tmp, $eol ); $len = hexdec ( substr ( $tmp, 0, $pos ) ); if ( isset ( $info['content-encoding'] ) ) { $str .= gzinflate ( substr ( $tmp, ( $pos + $add + 10 ), $len ) ); } else { $str .= substr ( $tmp, ( $pos + $add ), $len ); } $tmp = substr ( $tmp, ( $len + $pos + $add ) ); $check = trim ( $tmp ); } while ( ! empty ( $check ) ); } else if ( isset ( $info['content-encoding'] ) ) { $str = gzinflate ( substr ( $tmp, 10 ) ); } else { $str = $tmp; } return $str; } ?> http://php.net/manual/en/function.fsockopen.php

« previous php.notes (#142297) next »