如何解决这个问题,应该是URL转义的问题,详细请看。

lostmoon 2015-08-20 09:03:04
我往数据库某字段存入了一个值,是字符行,值是 http://img21.imgtn.bdimg.com/it/u=2964593467,576387895&fm=21&gp=0.jpg

但是,当从数据库读出来的时候,值却变成了,http://img2.imgtn.bdimg.com/it/u=2964593467,576387895&fm=21>0.jpg

也就是“&gp=”读出来的时候,变成了">"了,我想这应该是转义的问题吧?如何解决类似此类问题呢?请具体代码测试一下。谢谢@!

处理方法要有通用性,就是针对这种保存URL到数据库的,读取出来的时候,还能原样显示出来。
...全文
479 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
lyhoo163 2015-08-22
  • 打赏
  • 举报
回复
上机测试代码有效
lyhoo163 2015-08-22
  • 打赏
  • 举报
回复
Delphi中处理URL编码解码 1、uses HttpApp; 2、编码,先UTF8编码,然后再URL编码。 S2:=HttpEncode(UTF8Encode(S1)); 3、解码,先URL解码,然后再UTF8解码。 S1:=UTF8Decode(HttpDecode(S2)); 楼主参照收下代码修改自己程序,写入数据前实行“编码”操作,读取数据时返回“解码”操作就可以了:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,HttpApp,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    procedure FormShow(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormShow(Sender: TObject);
begin
  Edit1.Text:='http://img21.imgtn.bdimg.com/it/u=2964593467,576387895&fm=21&gp=0.jpg';
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  edit2.Text:=HttpEncode(UTF8Encode(Edit1.text));
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  edit3.Text:=UTF8Decode(HttpDecode(edit2.Text));
end;

end.

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧