global bytes() function returning the number of bytes of a string, independent of mbstring available and mbstring.func_overload set

This commit is contained in:
Ralf Becker 2007-09-29 09:17:42 +00:00
parent 645750297f
commit 82f2b4e91f
8 changed files with 24 additions and 26 deletions

View File

@ -1220,7 +1220,7 @@ class uiforms extends uical
else
{
$GLOBALS['egw']->browser =& CreateObject('phpgwapi.browser');
$GLOBALS['egw']->browser->content_header('event.ics','text/calendar',strlen($ical));
$GLOBALS['egw']->browser->content_header('event.ics','text/calendar',bytes($ical));
echo $ical;
$GLOBALS['egw']->common->egw_exit();
}
@ -1243,7 +1243,7 @@ class uiforms extends uical
{
$ical =& ExecMethod2('calendar.boical.exportVCal',$events,'2.0'/*$content['version']*/);
$GLOBALS['egw']->browser =& CreateObject('phpgwapi.browser');
$GLOBALS['egw']->browser->content_header($content['file'] ? $content['file'] : 'event.ics','text/calendar',strlen($ical));
$GLOBALS['egw']->browser->content_header($content['file'] ? $content['file'] : 'event.ics','text/calendar',bytes($ical));
echo $ical;
$GLOBALS['egw']->common->egw_exit();
}

View File

@ -438,7 +438,7 @@
{
$this->browser = CreateObject('phpgwapi.browser');
}
$this->browser->content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',strlen($def));
$this->browser->content_header('schema-backup-'.date('YmdHi').'.inc.php','text/plain',bytes($def));
echo "<?php\n\t/* eGroupWare schema-backup from ".date('Y-m-d H:i:s')." */\n\n".$def;
}
}

View File

@ -286,7 +286,7 @@
}
if(($success = $this->PutLine($this->request_method.' '.$request_uri.' HTTP/'.$this->protocol_version)))
{
if(($body_length = strlen($request_body)))
if(($body_length = bytes($request_body)))
{
$headers['Content-length'] = $body_length;
}

View File

@ -60,7 +60,7 @@
else
{
// $payload = '<?xml version="1.0"?\>' . "\n" . $this->serializeDebug() . $r->serialize();
// Header("Content-type: text/xml\r\nContent-length: " . strlen($payload));
// Header("Content-type: text/xml\r\nContent-length: " . bytes($payload));
// print $payload;
echo $r;
}

View File

@ -95,7 +95,7 @@
$payload = $GLOBALS['egw']->translation->convert("<?xml version=\"1.0\"?>\n" . $this->serializeDebug() . $r->serialize(),
$GLOBALS['egw']->translation->charset(),'utf-8');
header("Content-type: text/xml");
header("Content-length: " . $this->bytes($payload));
header("Content-length: " . bytes($payload));
echo $payload;
}
@ -121,24 +121,6 @@
}
}
/**
* mbstring.func_overload save strlen version: counting the bytes not the chars
*
* @param string $str
* @return int
*/
function bytes($str)
{
static $func_overload;
if (is_null($func_overload))
{
$func_overload = @extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
}
return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
}
/*
* add a method to the dispatch map
*/

View File

@ -28,6 +28,22 @@
* because they are required to be available at the lowest level. *
\***************************************************************************/
/**
* Return the number of bytes of a string, independent of mbstring.func_overload
* AND the availability of mbstring
*
* @param string $str
* @return int
*/
function bytes($str)
{
static $func_overload;
if (is_null($func_overload)) $func_overload = extension_loaded('mbstring') ? ini_get('mbstring.func_overload') : 0;
return $func_overload & 2 ? mb_strlen($str,'ascii') : strlen($str);
}
/**
* @internal Not to be used directly. Should only be used by print_debug()
*/

View File

@ -167,7 +167,7 @@
);
$payload = '<?xml version="1.0"?>' . "\n" . $r->serialize();
Header('Content-type: text/xml');
Header('Content-length: ' . strlen($payload));
Header('Content-length: ' . bytes($payload));
print $payload;
$GLOBALS['egw']->common->phpgw_exit(False);
}

View File

@ -117,6 +117,6 @@ $out = $server->getResponse($input, $params);
/* Return the response to the client. */
header('Content-Type: ' . $server->getResponseContentType());
header('Content-length: ' . strlen($out));
header('Content-length: ' . bytes($out));
header('Accept-Charset: UTF-8');
echo $out;