PHP,Javascript编码网址 [英] PHP, Javascript Encoding a url..
问题描述
我有一个如下所述的情况.
文件"a" Server.php:
从.txt文件中读取报告名称并回显它.
文件"b" Client.html:
向Server.php发送请求以读取文件并接收报告的名称(XmlHttpRequest.responsetext)
当我只是回显它时,这对于所有类型的报告和外语都适用,但是现在我想在Server.php中对报告名称进行编码,然后将其发送到Client.html.而且编码失败或没有给我我想要的文本.
I have a scenario as described below.
File "a" Server.php:
Reads a report name out of a .txt file and echo''s it.
File "b" Client.html:
Send a request to Server.php to read the file and receives the name of the report(XmlHttpRequest.responsetext)
This is working well for all types of reports and foreign languages when i just echo it, however now i want to encode the report name in Server.php and then send it to Client.html. And the encoding is failing or not giving me the text i want.
For Example:
The actual report name is:
Type [11432304]español Date10-26-2011-Time10-52-11
After encoding else where in the project it is:
Type+%5B11432304%5Despa%F1ol+Date10-26-2011-Time10-52-11
But when i encode it is:
%EF%BB%BFType+%5B11432304%5Despa%C3%B1ol+Date10-26-2011-Time10-52-11
Server.php
header( 'Content-Type: text/html; charset=utf-8' );
if(isset($_GET['read'])
{
$newfileNameandType = "Sample.txt"; //This is a notepad saved with [11432304]español Date10-26-2011-Time10-52-11 in utf-8 format.
if (file_exists($newfileNameandType))
{
$myfile=fopen($newfileNameandType,'r');
$NewReportAddress = fread($myfile, filesize($newfileNameandType));
fclose($myfile);
echo urlencode($NewReportAddress); // This is not giving me the correct encoded text like elsewhere.
}
}
?>
代码大师我缺少什么吗?当我编码但不是%EF%BB%BFType +%5B11432304%5Despa%C3%B1ol + Date10-26-"时,如何获得"Type +%5B11432304%5Despa%F1ol + Date10-26-2011-Time10-52-11" 2011-Time10-52-11.
感谢您的宝贵时间.
Code gurus am i missing something? How do i get "Type+%5B11432304%5Despa%F1ol+Date10-26-2011-Time10-52-11" when i encode but not "%EF%BB%BFType+%5B11432304%5Despa%C3%B1ol+Date10-26-2011-Time10-52-11".
Thanks for your time.
推荐答案
_GET [' 阅读']) {
_GET['read']) {
newfileNameandType = " ; // 这是一个用[11432304]españolDate10-26-2011-Time10-52-11保存在utf- 8种格式. 如果(文件存在(
newfileNameandType = "Sample.txt"; //This is a notepad saved with [11432304]español Date10-26-2011-Time10-52-11 in utf-8 format. if (file_exists(
newfileNameandType)) {
newfileNameandType)) {
这篇关于PHP,Javascript编码网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!