首页 \ 问答 \ htmlentities和htmlspecialchars拒绝处理字符串(htmlentities and htmlspecialchars refuse to process string)

htmlentities和htmlspecialchars拒绝处理字符串(htmlentities and htmlspecialchars refuse to process string)

自从我在Debian盒子上最后一次更新到PHP5 5.4.0-3以来,我注意到有些页面有空字段,其中MySQL数据库的文本应该是。

我玩了一下,发现了问题。

<?php
$scselect = mysql_query("SELECT `name` FROM `forum_threads` WHERE `forum` = '1' ORDER BY `timestamp` DESC") or exit((mysql_error()));
    while ($scrow=mysql_fetch_array($scselect))
    {
        var_dump($scrow['name']);
        var_dump(htmlentities($scrow['name']));
    }
?>

奇怪的是这是印刷的:

string(18) "php hu3: the Forum"
string(0) ""
string(18) "php hu2 score-rule"
string(0) ""
string(6) "php hu"
string(0) ""
string(15) "HU 8: Binarycnt"
string(0) ""

但如果我使用硬编码内容的htmlentities - > htmlentities(“test”); 它就像魅力一样。 如果我这样做:

var_dump("a".$scrow['name']);

它还说

string(0) ""

但它变得陌生。 如果我将htmlentities或htmlspecialchars与数据库中的任何其他变量一起使用,它就可以完美地运行。

var_dump(htmlspecialchars($scrow['ID'])); // prints for example string(2) "87"

这可能是什么原因?


Since the last update to PHP5 5.4.0-3 on my Debian box I noticed that some pages have empty fields where text from the MySQL database should be.

I played around a bit and found the problem.

<?php
$scselect = mysql_query("SELECT `name` FROM `forum_threads` WHERE `forum` = '1' ORDER BY `timestamp` DESC") or exit((mysql_error()));
    while ($scrow=mysql_fetch_array($scselect))
    {
        var_dump($scrow['name']);
        var_dump(htmlentities($scrow['name']));
    }
?>

strangely this is whats printed:

string(18) "php hu3: the Forum"
string(0) ""
string(18) "php hu2 score-rule"
string(0) ""
string(6) "php hu"
string(0) ""
string(15) "HU 8: Binarycnt"
string(0) ""

but if I use htmlentities with hardcoded content -> htmlentities("test"); it works like charm. Also if I do this:

var_dump("a".$scrow['name']);

it also says

string(0) ""

But it gets stranger. If I use htmlentities or htmlspecialchars with any other variable from the database it works just perfectly.

var_dump(htmlspecialchars($scrow['ID'])); // prints for example string(2) "87"

what can be the cause of this?


原文:https://stackoverflow.com/questions/10054513
更新时间:2022-03-30 11:03

最满意答案

我认为Criteria部分并不完全正确。 也没有定义日。 你已经定义了DT。

string customer_id = "54sdfjghwegFDqwgf";   
DateTime day = DateTime.Parse("2011-10-31");   
var criteria = TheSession.CreateCriteria(typeof(user_data))  
  .Add(Restrictions.Eq("user_id", customer_id))  
  .Add(Restrictions.Eq("Day", day))   
  .List<user_data>();   

Thanks to everyone who tried to help me out!

Unfortunately, I had to use raw sql query: using CreateSQLQuery and then adding Scalars for each field.

相关问答

更多
  • 草拟的代码应如下所示: // left side var left = Projections.Property(ti => ti.PeriodFrom); // right side var right = Projections.SqlFunction("COALESCE" , NHibernateUtil.DateTime , Projections.Constant(search.DateFrom, NHibernateUtil.Date ...
  • 这有点令人讨厌,但您也可以使用ADDTIME()以负值: SELECT * FROM table WHERE date_col> ADDTIME(NOW(),'-0:5:0'); It's kind of nasty, but you can also use ADDTIME() with a negative value: SELECT * FROM table WHERE date_col > ADDTIME(NOW(), '-0:5:0');
  • string dt; string dt2; DateTime date = DateTime.Now; DateTime date2 = DateTime.Now; dt = date.ToLongTimeString(); // display format: 11:45:44 AM dt2 = date2.ToShortDateString(); // display format: 5/22/2010 ...
  • NHibernate是一个对象/关系映射器,因此要正确地询问“我该如何编写此查询”问题,您需要提供足够的信息,以便潜在的回答者可以理解这三件事情是什么样的: NHibernate实体类(这是Object部分) 数据库表(这是关系部分) 映射 ,无论是HBM.XML,FluentNH等。 让我们假设您的实体看起来像这样: public class AccountProfile { public virtual int Id { get; set; } public virtual string ...
  • 您可以在C#中使用bool,并使用自定义IUserType实现将其映射到MySQL中的字符。 这个例子正是你想要的。 You can use a bool in C# and map it to a char in MySQL using a custom IUserType implementation. This example is exactly what you're looking for.
  • 所以我发现了问题,当我安装MySQL时发生了一些事情并且c#连接工具没有正确安装。 一旦卸载Mysql连接C#并树脂安装它,更新项目引用并且它工作。 So I have identified the problem, when I installed MySQL something happened and the c# connection tools did not install correctly. Once Uninstalled Mysql connect for C# and resinsta ...
  • 我认为Criteria部分并不完全正确。 也没有定义日。 你已经定义了DT。 string customer_id = "54sdfjghwegFDqwgf"; DateTime day = DateTime.Parse("2011-10-31"); var criteria = TheSession.CreateCriteria(typeof(user_data)) .Add(Restrictions.Eq("user_id", customer_id)) .Add(Restr ...
  • 在DateTime/Time/DateTimeOffset/Date数据类型中,我总是明确地告诉映射中的预期类型,因为从底层属性类型(.Net缺少Date类型,...)推断时可能存在一些歧义。 通常对于db DateTime ,我在属性映射上指定NHibernate类型timestamp 。 请参阅NHibernate参考文档中可用的类型列表。 根据您的使用情况,有许多可供选择的类型。 您也可以指定一些非NHibernate类型,如NHibernate参考文档中所述 。 On DateTime/Time/D ...
  • 没有必要存储您的数字和DateTime值。 你有一个坏习惯踢 。 将列更改为整数类型和日期时间类型。 并且没有必要在列名中使用单引号。 只需删除它们。 还可以使用using语句自动配置连接,命令和阅读器,而不是手动调用Close方法。 using(var con = new MySqlConnection(conString)) using(var stm = con.CreateCommand()) { stm.CommandText = "SELECT * FROM history WHERE n ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)