首页 \ 问答 \ 从ISO-8859-1到UTF-8的PHP编码(PHP encoding from ISO-8859-1 to UTF-8)

从ISO-8859-1到UTF-8的PHP编码(PHP encoding from ISO-8859-1 to UTF-8)

<?php
mb_internal_encoding('UTF-8');
mb_language('uni');
$a=file_get_contents("http://www.ciao.de/Erfahrungsberichte/8x4_Wild_Flower_Deo_Spray__8937431");
preg_match('/dass auf dem Versch(.*)ziehen mich/Us',$a,$b);
$b=$b[1];
echo $b."\n";
echo utf8_encode($b)."\n";
echo mb_convert_encoding($b,'UTF-8','iso-8859-1')."\n";

结果是

lussdeckel riesengro▒ und un▒bersehbar glitzernd ein ▒New▒ prangt. Neue Produkte
lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte
lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte

HTTP源代码在meta标签中建议使用“iso-8859-1”。 德语变音符号很好,但为什么“New”引号没有正确转换? 在PHP 手册中有一个函数fix_latin。 使用此功能时,引号也可以正确转换!

PS:与欧洲货币符号€(EUR)相同 - 它也被错误地转换(除了使用fix_latin函数),但为什么?


<?php
mb_internal_encoding('UTF-8');
mb_language('uni');
$a=file_get_contents("http://www.ciao.de/Erfahrungsberichte/8x4_Wild_Flower_Deo_Spray__8937431");
preg_match('/dass auf dem Versch(.*)ziehen mich/Us',$a,$b);
$b=$b[1];
echo $b."\n";
echo utf8_encode($b)."\n";
echo mb_convert_encoding($b,'UTF-8','iso-8859-1')."\n";

results in

lussdeckel riesengro▒ und un▒bersehbar glitzernd ein ▒New▒ prangt. Neue Produkte
lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte
lussdeckel riesengroß und unübersehbar glitzernd ein �New� prangt. Neue Produkte

HTTP source code suggests in meta tag to use "iso-8859-1". German umlauts are fine, but why are the quotes around "New" not converted correctly? In PHP manual there is a function fix_latin. When using this function the quotes are also converted correctly!?

PS: same occurs with european currency symbol € (EUR) - it's also converted wrong (except with the fix_latin function), but why?


原文:https://stackoverflow.com/questions/6489268
更新时间:2023-09-29 20:09

最满意答案

这是一个解决方案。 在主窗口小部件内部绘制一个绘图小部件,似乎可以工作,并且可以使用setGeometry控制位置。

self.main_widget = QtGui.QWidget(self)
self.plot_widget = QtGui.QWidget(self.main_widget)
self.plot_widget.setGeometry(250,180,500,600)
self.figure = plt.figure()
self.plotting = FigureCanvas(self.figure)
self.plot()
plot_box = QtGui.QVBoxLayout()
plot_box.addWidget(self.plotting)
self.plot_widget.setLayout(plot_box)

Here is a solution. Make a plot widget inside of the main widget, seems to work and can control position with setGeometry.

self.main_widget = QtGui.QWidget(self)
self.plot_widget = QtGui.QWidget(self.main_widget)
self.plot_widget.setGeometry(250,180,500,600)
self.figure = plt.figure()
self.plotting = FigureCanvas(self.figure)
self.plot()
plot_box = QtGui.QVBoxLayout()
plot_box.addWidget(self.plotting)
self.plot_widget.setLayout(plot_box)

相关问答

更多
  • 由于你的matplotlib依赖于PyQt4,你需要强制Matplotlib使用PyQt5后端。 喜欢这个: import matplotlib matplotlib.use("Qt5Agg") 这个函数必须在第一次导入pyplot 之前调用; 或者,如果您不使用pyplot,则必须在导入matplotlib.backends之前调用它。 As your matplotlib depends on PyQt4, you need to force Matplotlib to use PyQt5 backe ...
  • 实际上并不复杂 相关的Qt小部件在matplotlib.backends.backend_qt4agg 。 FigureCanvasQTAgg和NavigationToolbar2QT通常是您需要的。 这些是常规的Qt小部件。 你把它们视为任何其他小部件。 下面是一个非常简单的例子,其中包括Figure , Navigation和单个按钮,可以绘制一些随机数据。 我已经添加了评论来解释事情。 import sys from PyQt4 import QtGui from matplotlib.backen ...
  • 您还可以在链接到的问题中看到, FuncAnimation需要一个方法作为其第二个参数。 但是在你的调用中你提供了None (因为self.animate_loop()计算结果为None )。 将此更改为 self.anim = animation.FuncAnimation(fig, self.animate_loop, interval=optimal_frequency) 其次,从链接的问题也可以看出, self.animate_loop需要进行参数,所以你可能需要将此更改为 def animate ...
  • 这是一个解决方案。 在主窗口小部件内部绘制一个绘图小部件,似乎可以工作,并且可以使用setGeometry控制位置。 self.main_widget = QtGui.QWidget(self) self.plot_widget = QtGui.QWidget(self.main_widget) self.plot_widget.setGeometry(250,180,500,600) self.figure = plt.figure() self.plotting = FigureCanvas(self. ...
  • 我的猜测是你使用Python-2,其中/运算符对于整数的行为与浮点的行为不同。 在第一种情况下,它是一个整数除法:结果是一个整数,其余部分被丢弃。 在第二种情况下,这是您通常期望从部门得到的结果。 这是很多错误的来源,所以在Python-3中, /运算符总是一个常规分区(返回一个浮点数),整数除法可以用//完成。 欲了解更多详情,请参阅PEP-238 。 请注意,您的calSaturationCurrent函数包含这样一个整数除法: 1/Tc在Python-2中产生0。 为了使Python-2的行为像Pyt ...
  • 您在matplotlib发现了一个有趣的错误。 Qt4后端不会清除重绘前用于显示图形的qImage ,因此您可以看到阴影的原因。 这可以通过向matplotlib.backends.backed_qt4Agg.FigureCanvasQTAgg.paintEvent添加几行来轻松解决。 def paintEvent(self, e): """ Copy the image from the Agg canvas to the qt.drawable. In Qt, all drawi ...
  • 嘿,我搜索了解决方案,但找不到任何好的提示。 但后来我试着用代码玩一点。 不知何故它现在有效(问题是线ax.hold(假): 如果您这样称呼它(来自您的问题的代码): data = [{'med': 6.0, 'q1': 4.0, 'q3': 8.0, 'whislo': 3.0, 'whishi': 10.0, 'fliers': [20, 1]}] ax = self.figure.add_subplot(111) ax.hold(False) // call hold BEFORE bxp(data) ...
  • 感谢@ImportanceOfBeingErnest(请参阅问题下面的评论),我自己想清楚了。 任何人偶然发现这个问题的答案都是这样。 如果你想在matplotlib中使用PyQt5在个人窗口中创建图形,那么对于大多数人来说,这种方法就是运行matplotlib.use('Qt5Agg')然后是%matplotlib qt5 。 由于某些原因,我仍然不知道这对我来说不起作用。 但是,解决方法是检查以下两个文件:/. /.ipython/ipython_config.py和/.ipython/ipython_ ...
  • 我不清楚你是否想使用PySide或PyQt ,但在任何一种情况下问题是你想使用一个,但是matplotlib正在使用另一个设置Qt4后端,因此看起来令人困惑的错误。 如果你想使用PySide确认 backend.qt4 : PySide # PyQt4 | PySide 在你的matplotlibrc文件中。 如果你想使用PyQt确认 backend.qt4 : PyQt4 # PyQt4 | PySide 在你的matplotlibrc文件中。 I am not clear ...
  • 听起来你的问题是,“我怎样才能让饼图坐在我的身影中间?”。 我将回答: 您正在使用QT4窗口系统来制作您的情节这一事实并不特别。 我已经采用了matplotlib饼图示例,并修改了图形宽度以模拟您的要求。 最后,至关重要的是,我将宽高比设置为1:1以保持饼图为圆形: from pylab import * # make a square figure and axes figure(1, figsize=(10, 3)) ax = axes([0.1, 0.1, 0.8, 0.8]) labels = ...

相关文章

更多

最新问答

更多
  • 您如何使用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)