我在编写PHP时遇到麻烦.
我有一个JavaScript/jQuery HTML5页面使用$ .post与我的PHP脚本交互.但是,PHP面临着一个奇怪的问题,可能与编码有关.
当我写作
htmlentities("í")
Run Code Online (Sandbox Code Playgroud)
我希望PHP输出í.然而,相反它输出í
在开始时,我认为我在编码时犯了一些错误
htmlentities("í")=="í"?"Good":"Fail";
Run Code Online (Sandbox Code Playgroud)
正在输出"失败",其中
htmlentities("í")=="í"?"Good":"Fail";
Run Code Online (Sandbox Code Playgroud)
但htmlentities($search, null, "utf-8")按预期工作.
我想让PHP与MySQL服务器通信,但它也有编码问题,即使我使用utf8_encode.我该怎么办?
编辑:在SQL命令,写
SELECT id,uid,type,value FROM users,profile
WHERE uid=id AND type='name' AND value='XXX';
Run Code Online (Sandbox Code Playgroud)
其中XXX不包含任何字符,按预期工作,但如果有任何'í'字符则不然.
SET NAMES 'utf8';
SET CHARACTER SET 'utf8';
SELECT id,uid,type,value FROM users,profile
WHERE uid=id AND type='name' AND value='XXX';
Run Code Online (Sandbox Code Playgroud)
不仅没有íchars,但它也没有任何"特殊"字符的字符串失败.从SET NAMES和SET CHARACTER SET中删除'字符似乎没有任何改变.
我使用PDO连接到MySQL数据库.
编辑2:我正在使用XAMPP for Linux的MySQL版本5.1.30.
编辑3:SHOW VARIABLES LIKE '%character%'从PhpMyAdmin输出运行
character_set_client utf8
character_set_connection utf8
character_set_database latin1
character_set_filesystem binary
character_set_results utf8
character_set_server latin1
character_set_system utf8
character_sets_dir /opt/lampp/share/mysql/charsets/
Run Code Online (Sandbox Code Playgroud)
从我的PHP脚本(带有print_r)运行相同的查询输出: …
我正在研究用Java编写的应用程序.
我想允许用户阅读应用程序的"帮助".
我基本上是在寻找一个免费的Java免费开源软件.我希望它支持"查找"和树状结构.
我愿意自己编写一个组件,但我想知道在尝试重新发明轮子之前是否已存在替代品...
有没有可用的选择?
我正在运行在谷歌搜索时发现的以下示例代码:
SELECT MD5(RAND())
Run Code Online (Sandbox Code Playgroud)
但是,令我惊讶的是,MD5返回的是纯数字,而不是十六进制数字。使用CONV(MD5(RAND()), 10, 16)似乎可以解决我的问题,但是MySQL文档指出MD5函数应该返回已经为十六进制的字符串。
难道我做错了什么?
EDIT2:这个问题似乎仅存在于phpMyAdmin,而不是MySQL的命令行版本。
编辑:我的MySQL版本:
mysql --version
mysql Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (x86_64) using readline 6.1
Run Code Online (Sandbox Code Playgroud)
MD5值示例:
6338666264663132376461666163313063656535633666616266396530613335
Run Code Online (Sandbox Code Playgroud)
另外,CONV返回一个非常短的字符串,例如:
B9
Run Code Online (Sandbox Code Playgroud)
该字符串通常是一位数字,而到目前为止,我得到的最长是5位数字。
我正在做一些C#IO工作,我想从几个类导入/导出数据.在寻找一段时间后,似乎序列化非常接近我想要的.
但是,有一个问题.我有一个XML文件,它描述了某个类的成员(我将其称之为ValueWithId),它们聚合在一个类中,我将CollectionOfValuesWithId为此问题调用它.
ValueWithId是一个包含string被调用成员的类ShortName,它是唯一的.只有一个ShortName每ValueWithId和所有ValueWithId具有非空ShortName.CollectionOfValuesWithId包含一个ValueWithId用给定的函数来查找ShortName.
序列化的时候,我做不想要存储ValueWithId也不CollectionOfValuesWithId输出文件.相反,我只想将其存储ShortName在文件中.到现在为止还挺好.我只需要使用SerializationInfo.AddValue("ValueWithId", MyValueWIthId.ShortName).
问题出在反序列化上.一些谷歌搜索表明,要从文件中读取数据,可以这样做:
public SomeClassThatUsesValueWithId(SerializationInfo info, StreamingContext ctxt)
{
string name = (string)info.GetValue("ValueWithId", typeof(string));
}
Run Code Online (Sandbox Code Playgroud)
但是,字符串不足以恢复ValueWithId实例.我也需要CollectionOfValuesWithId.我想要这样的东西:
public SomeClassThatUsesValueWithId(SerializationInfo info,
StreamingContext ctxt, CollectionOfValuesWithId extraParameter)
Run Code Online (Sandbox Code Playgroud)
换句话说,我需要将额外的数据传递给反序列化构造函数.有没有人知道做这个或任何替代方案的方法?
我正在使用我使用的代码结构的问题,如下(简化):
class SPoint
{
public:
SPoint(double x, double y, double z) : _x(x), _y(y), _z(z) {}
protected:
double _x, _y, _z;
}
class Point3D : public SPoint
{
public:
Point3D(double x, double y, double z) : SPoint(x, y, z) { // default values for U and V }
protected:
double U, V;
}
Run Code Online (Sandbox Code Playgroud)
这些点用于创建折线:
class SPolyline
{
public:
SPolyline(const vector<shared_ptr<SPoint>>& points) { // points are cloned into _points}
protected:
vector<shared_ptr<SPoint>> _points;
};
class Polyline3D : SPolyline
{
public :
Polyline3D(const …Run Code Online (Sandbox Code Playgroud) 我正在使用System.Reflection.Emit,在某些时候我想从MethodBuilder创建一个委托:
MethodBuilder fooBuilder = createFooMethodBuilder();
ILGenerator ilGenerator = ...
Type delegateType = typeof(DelegateType);
LocalBuilder delegateVar = ilGenerator.DeclareLocal(delegateType);
//Somehow create emit instructions to create delegate from fooBuilder
//Store delegate in delegateVar using
Run Code Online (Sandbox Code Playgroud)
我可以发现从静态函数创建委托使用这样的东西:
ldnull
ldftn void class Test.MainClass::bar()
newobj instance void class Test.DelegateType::'.ctor'(object, native int)
Run Code Online (Sandbox Code Playgroud)
但是现在我被卡住了.我需要一种方法来修改MethodBuilder然后我需要一种方法来发出以下行的指令.我不知道如何获得一个接受原生int的构造函数.
有什么建议?
据我所知,Windows API使用"类",依赖于WNDCLASS/WNDCLASSEX结构.
我已成功通过Windows API Hello World应用程序,并了解此类由我们自己的窗口使用,但也由Windows核心控件使用,如"编辑","按钮"等.我也理解它与某种方式有关WndProc(它允许我为它定义一个函数)
虽然我可以找到关于这个类的文档,但我找不到任何解释这个概念的东西.
到目前为止,我发现的唯一一件事是:
Window类与C++类没有任何关系.
这实在不利于(它告诉我它是什么不是,但不Tellme公司它是什么的).事实上,这只会让我更加困惑,因为我很想将WNDCLASSEX与C++类联系起来,并认为"WNDCLASSEX"代表一种控件类型 .那么,我的第一个问题是它是什么?
第二,我明白可以在类中定义WndProc.但是,窗口也可以从子控件(或窗口,或Windows API中调用它们)中获取消息.怎么会这样?
最后,何时定义新类是一种很好的编程习惯?每个应用程序(对于主框架),每帧,我定义一个控件(如果我创建自己的进度条类,例如)?
我知道Java/Swing,C#/ Windows.Form,C/GTK +和C++/wxWidgets,所以我可能会理解与这些工具包的比较.
我正在研究一种文件格式,应该在几种不同的操作系统和计算机上编写和读取.其中一些计算机应该是x86计算机,其他计算机应该是x86-64.其他一些处理器可能存在,但我不关心他们还没有.
此文件格式应包含几个可读取的数字,如下所示:
struct LongAsChars{
char c1, c2, c3, c4;
};
long readLong(FILE* file){
int b1 = fgetc(file);
int b2 = fgetc(file);
int b3 = fgetc(file);
int b4 = fgetc(file);
if(b1<0||b2<0||b3<0||b4<0){
//throwError
}
LongAsChars lng;
lng.c1 = (char) b1;
lng.c2 = (char) b2;
lng.c3 = (char) b3;
lng.c4 = (char) b4;
long* value = (long*) &lng;
return *value;
}
Run Code Online (Sandbox Code Playgroud)
写作:
void writeLong(long x, FILE* f){
long* xptr = &x;
LongAsChars* lng = (LongAsChars*) xptr;
fputc(lng->c1, f);
fputc(lng->c2, f);
fputc(lng->c3, …Run Code Online (Sandbox Code Playgroud) 我有以下Antlr语法:
grammar MyGrammar;
doc : intro planet;
intro : 'hi';
planet : 'world';
MLCOMMENT
: '/*' ( options {greedy=false;} : . )* '*/' { $channel = HIDDEN; };
WHITESPACE : (
(' ' | '\t' | '\f')+
|
// handle newlines
( '\r\n' // DOS/Windows
| '\r' // Macintosh
| '\n' // Unix
)
)
{ $channel = HIDDEN; };
Run Code Online (Sandbox Code Playgroud)
在ANTLRWorks 1.2.3解释器,输入hi world,hi/**/world和hi /*A*/ world工作,符合市场预期.
但是,hiworld也应该接受不应该起作用的输入.我怎么做hiworld失败?如何在"hi"和"world"之间强制至少有一个空格(或注释)? …
我在System.Reflection.Emit使用mono 导出的程序集中遇到了一个奇怪的错误.在尝试运行我的程序集时,我得到一个InvalidProgramException:无效的IL代码.
monodis 给我这个CIL结果(这与我用Emit导出的结果一致):
.method public static hidebysig
default void f_main (class [Pine.Core]Pine.Core.Function A_0, class [Pine.Core]Pine.Core.ValueList A_1) cil managed
{
// Method begins at RVA 0x2144
// Code size 26 (0x1a)
.maxstack 4
.locals init (
class [Pine.Core]Pine.Core.Function V_0,
class [Pine.Core]Pine.Core.IScope V_1,
class [Pine.Core]Pine.Core.ValueList V_2,
class [Pine.Core]Pine.Core.IScope V_3)
IL_0000: ldarg.0
IL_0001: stloc.0
IL_0002: ldarg.1
IL_0003: stloc.2
IL_0004: ldloc.0
IL_0005: ldftn instance class [Pine.Core]Pine.Core.IScope class [Pine.Core]Pine.Core.Function::get_Scope()
IL_000b: stloc.1
IL_000c: ldloc.1
IL_000d: newobj instance void class [Pine.Core]Pine.Core.BlockScope::'.ctor'(class [Pine.Core]Pine.Core.IScope) …Run Code Online (Sandbox Code Playgroud) .net ×3
c ×2
c# ×2
mysql ×2
antlr ×1
api ×1
c++ ×1
channel ×1
chm ×1
cil ×1
delegates ×1
encoding ×1
exception ×1
hex ×1
hidden ×1
ignore ×1
inheritance ×1
io ×1
java ×1
long-integer ×1
md5 ×1
mono ×1
open-source ×1
php ×1
phpmyadmin ×1
shared-ptr ×1
utf-8 ×1
whitespace ×1
winapi ×1
wndproc ×1