在PHP中运行的get_browser()方法中获取非法字符 [英] Getting illegal characters in get_browser() method run in php

查看:95
本文介绍了在PHP中运行的get_browser()方法中获取非法字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



根据那里的信息和在 https://bugs.debian.org/cgi-bin/bugreport.cgi?bug = 612364 可以更彻底地解释该错误,我创建了一些解决问题的代码。



我在这里和那里都张贴了答案。



代码:

  if(function_exists('get_browser')&& ini_get(’browscap’)){
$ browser_info = get_browser(null,true);
if(function_exists('mb_convert_encoding'))$ browser_info ['browser_name_regex'] = mb_convert_encoding($ browser_info ['browser_name_regex'], UTF-8, ISO-8859-1);
print_r($ browser_info);
}


From the manuals I am running a simple code to fetch browser info using get_browser() method.

Code in the manuals -

Code I am running(almost same/i tried by removing echo "<pre>"; but no effect) -

<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";
print_r($browser);
?>

This is the error/illegal characters I am getting at browser_name_regex -

I also tried this UTF 8 encoding for characters, but problem still persist.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test browser</title>
</head>

<body>
<?php
echo $_SERVER['HTTP_USER_AGENT'] . "\n\n";

$browser = get_browser(null, true);
echo "<pre>";
print_r($browser);
?>
</body>
</html>

Let me know what I am doing wrong and where to look for the solution?

One thing more to ask, in the same doc -

Attempts to determine the capabilities of the user's browser, by looking up the browser's information in the browscap.ini file.

Where do I find this browscap.ini in my system I am using Windows 7...although I am not very sure if it is related with this problem or not.

解决方案

The same question has been asked at PHP - get_browser() results

Based on the information there and the information found at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=612364 which explains the bug more throughly, i've created some lines of code which solves the problem.

I've posted my answer both here and there.

Code:

if (function_exists('get_browser') && ini_get('browscap')) {
    $browser_info = get_browser(null, true);
    if (function_exists('mb_convert_encoding')) $browser_info['browser_name_regex'] = mb_convert_encoding($browser_info['browser_name_regex'], "UTF-8", "ISO-8859-1");
    print_r($browser_info);
}

这篇关于在PHP中运行的get_browser()方法中获取非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆