Table of Contents
回复讨论(解决方案)

神奇的%EF%BB%BF

Jun 23, 2016 pm 01:28 PM

废话不多说上代码:
前台:

function on_post_form(){	var f = document.post_myform;	var s_paramName = document.getElementById("select_paramName").value;        f.action = "__APP__/index/select_infomessage-s_paramName-"+encodeURIComponent(s_paramName)+".html";        f.submit();}<input name="select_paramName" class="KeyWord" id="select_paramName" size="20" maxlength="30" type="text"><div id="searchresult" style="display: none;"></div>
Copy after login

$(document).ready(function(){ $('#select_paramName').keyup(function(){   //输入框的id为search,这里监听输入框的keyup事件  $.ajax({     type:"GET",     //AJAX提交方式为GET提交	   url:"__APP__/index/get_search_showdiv",   //处理页的URL地址	   data:"s_Name="+encodeURIComponent($('#select_paramName').val()),   //要传递的参数	   success:function(data){   //成功后执行的方法	      if(data != ""){				var ss;				ss = data.split("@");   //分割返回的字符串				var layer;				layer = "<table>";     //创建一个table				for(var i=0;i<ss.length-1;i++){				 layer += "<tr><td class='line'>"+ss[i]+"</td></tr>";				}				layer += "</table>";				$('#searchresult').empty();  //先清空#searchresult下的所有子元素				$('#searchresult').append(layer);//将刚才创建的table插入到#searchresult内				$("#searchresult").css("display", "");				$('.line').hover(function(){  //监听提示框的鼠标悬停事件				 $(this).addClass("hover"); 				},function(){				 $(this).removeClass("hover");				});				$('.line').click(function(){  //监听提示框的鼠标单击事件				 $('#select_paramName').val($(this).text());				 $("#searchresult").css("display", "none"); 				 ChangeCoords();				});			   }else{				$('#searchresult').empty();			   }	   }  }); });});
Copy after login


后台:
public function get_search_showdiv()	{	   //urlencode urldecode 文本框自动提示	   $keyword = urldecode($_GET['s_Name']);	   $condition = "f_hotname like '%".$keyword."%'";	   $info=$this->model->table('forest')->field('f_hotname')->where($condition)->order('f_id desc')->limit(5)->select();	   if($keyword !=""){		   foreach($info as $vo)     		   {      			 echo $vo['f_hotname'].'@';    		   } 	   }else{	       		   echo "";	   }	}
Copy after login


问题症状:比如输入“百度”    
在div   #searchresult   里显示:
百度杀毒
百度卫士
百度影音

如果选择第一项百度杀毒,火狐浏览器这样显示:
http://192.168.1.101/index/select_infomessage-s_paramName-%EF%BB%BF%百度杀毒.html
什么也没有。。。
如果选择第二项百度卫士,火狐浏览器这样显示:
http://192.168.1.101/index/select_infomessage-s_paramName-百度卫士.html
正常搜索,可以搜索到信息。其它项也是正常,唯独第一项就不正常。

度娘说是bom头,我所有页面都是去bom头的,编码也是utf8,尝试了很多也解决不了问题。
为什么会在第一项时候会加入%EF%BB%BF%,,,,, 在其它项都可以正常显示的。


回复讨论(解决方案)

%EF%BB%BF 不就是 BOM 头的 url 编码吗?
因为只有一个,所以你程序加载的文件中,只有一个有 BOM 头

public function get_search_showdiv()
这个函数所在php脚本文件有BOM

%EF%BB%BF 不就是 BOM 头的 url 编码吗?
因为只有一个,所以你程序加载的文件中,只有一个有 BOM 头



不好意思,这几天出差,刚刚回来,什么意思,没看明白。

utf-8 文件的 BOM 头的十六进制表示是 EFBBBF
url 编码后是 %EF%BB%BF

ajax 请求的 url 为 __APP__/index/get_search_showdiv
显然这是在使用框架

框架在处理一个请求时,至少会加载 3 个文件
所以任何一个被加载的文件有 BOM 头,返回的内容就会有 BOM 头

连接变成 ....%EF%BB%BF百度杀毒.html
而不是 ....%EF%BB%BF%EF%BB%BF百度杀毒.html
就表示只有一个文件有 BOM 头

ajax 收到的是形如 xxx@xxx@xxx@ 的串
BOM 当然是附加在内容前面的: BOMxxx@xxx@xxx@
拆分成数组后,自然是只有第一项有 BOM 啦

那怎么解决这个问题呢

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1664
14
PHP Tutorial
1269
29
C# Tutorial
1248
24
PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Explain secure password hashing in PHP (e.g., password_hash, password_verify). Why not use MD5 or SHA1? Apr 17, 2025 am 12:06 AM

In PHP, password_hash and password_verify functions should be used to implement secure password hashing, and MD5 or SHA1 should not be used. 1) password_hash generates a hash containing salt values ​​to enhance security. 2) Password_verify verify password and ensure security by comparing hash values. 3) MD5 and SHA1 are vulnerable and lack salt values, and are not suitable for modern password security.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

How does PHP type hinting work, including scalar types, return types, union types, and nullable types? How does PHP type hinting work, including scalar types, return types, union types, and nullable types? Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles