Baidu provides free search code for us to call Baidu's search function on our website. For details, refer:
Http://www.baidu.com/search/freecode.html
In actual use, many friends encounter garbled code problems. How can this problem be solved?
The most likely cause of the garbled problem is the UTF-8 code that your website uses, while Baidu uses gb2312 encoding, so you need to specify the encoding we need in the custom code, the method is to add a hidden form item to the form:
<Input name = "ie" type = "hidden" value = "UTF-8">
The final code is as follows:
<Form action = "http://www.baidu.com/baidu” name =" Baidu ">
<Input name = "tn" type = "hidden" value = "Baidu">
<Input name = "ie" type = "hidden" value = "UTF-8">
<Input type = "text" name = "word" size = "30">
</Form>
In actual application, we may not need to use form submission, but want to directly reference the search link. For example, we want to get the search result of "freehand Internet, so we want to construct a link: http://www.baidu.com/s? WD = freehand Internet
But garbled characters will occur during access. In this case, we can add a URL option "Ie = UTF-8" to the link to solve the Garbled text problem. Such as: http://www.baidu.com/s? WD = freehand Internet & Ie = UTF-8