str_replace()无法按预期工作(str_replace() doesn't work as expected)
我有一个像这样的字符串:
$string = "somehting<br><br>";
当我像这样尝试
str_replace()
:echo str_replace("<br>","<c>",$string);
输出字符串根本不会改变。
我试过的:
echo mb_detect_encoding($string); // returns UTF-8 var_dump(strpos($string, "<br>")); // bool(false)
我之前用html dom节点类编辑了字符串,现在我真的不知道出了什么问题。
我试图在sandbox.onlinephpfunctions.com上用真正的字符串重现问题并且它有效。
所以我无法重现这个问题。
I have a string like this :
$string = "somehting<br><br>";
When I try
str_replace()
like this:echo str_replace("<br>","<c>",$string);
The output string doesn't change at all.
What I tried:
echo mb_detect_encoding($string); // returns UTF-8 var_dump(strpos($string, "<br>")); // bool(false)
I have edited the string with html dom node class before and now I really don't know what is wrong.
I have tried to reproduce the problem on sandbox.onlinephpfunctions.com with real string and it works.
So I am unable to reproduce the problem.
原文:https://stackoverflow.com/questions/31720138
最满意答案
XML文件似乎被转换为错误的单字节编码。 检查使用
Reader/Writer/String.getBytes/new String
始终指定charset。 永远不要使用FileReader/FileWriter
。The XML file seems to be converted to a wrong single-byte encoding. Check that using
Reader/Writer/String.getBytes/new String
always a charset is specified. Do never useFileReader/FileWriter
.
相关问答
更多-
没有代码可以查看,很难确定原因。 我可以告诉你,异常意味着发送的字节被假定为UTF-8编码,但是你发送的文件,或者至少是IE试图发送的文件,不是UTF-8编码的。 Not having code to look at, its hard to pin down the exact cause. I can tell you that exception means that the bytes sent were assumed to be UTF-8 encoded, but the file you a ...
-
我在这样的视图中解决了它: The link #{content_tag(:span, @not_found_path.force_encoding("ISO-8859-1").encode("utf-8"), :class => 'text-error')} is not found, We are sorry for that, as we have migrated our website, we could not restore all the links. 我希望这对一些人有所帮助 I've ...
-
尝试在带有BOM的UTF-8中保存有问题的文件(可能是rake正在尝试的任何东西)。 Try saving the offending file (could be anything that rake is trying) in UTF-8 WITH BOM.
-
当我执行Build项目时,3字节UTF-8序列的字节2无效(Invalid byte 2 of a 3-byte UTF-8 sequence when i execute the Build project)[2023-09-06]
XML文件似乎被转换为错误的单字节编码。 检查使用Reader/Writer/String.getBytes/new String始终指定charset。 永远不要使用FileReader/FileWriter 。 The XML file seems to be converted to a wrong single-byte encoding. Check that using Reader/Writer/String.getBytes/new String always a charset is sp ... -
更新固定在运行循环开发。 运行循环中有一个错误。 "Dilbert’s MacBook Pro [
]" $ perl -ane '{ if(m/[[:^ascii:]]/) { print } }' devices.txt Dilbert’s MacBook Pro [ ] 该字符串中的撇号导致了问题。 它是一个UTF8字符而不是ASCII。 解决方法在系统偏好设置>共享中重命名您的机器。 跟踪 https://github.com/calabash/run_loop/issue ... -
UTF-8中的Ruby无效字节序列(ArgumentError)[重复](Ruby invalid byte sequence in UTF-8 (ArgumentError) [duplicate])[2024-03-13]
没有正确理解上述帖子的内容。 至少这可以用作本文的实现示例 require 'find' count = 0 Find.find('/Users/Anconia/') do |file| # '/' for root directory on OS X if file =~ /\b(\.txt|\.doc|\.docx)\b/ ... -
如果您知道文件的正确编码并且它不是“utf-8”,那么您可以将其添加到xml标头: 或者将其解析为读者: db.parse(new InputStreamReader(new FileInputStream(new File(xmlFileName)), "[correct encoding here]")); if you know the correct encoding of the ...
-
Ruby和Nokogiri中UTF-8错误的无效字节序列(invalid byte sequence in UTF-8 error with Ruby and Nokogiri)[2022-06-13]
可达性问题不得不重新安装最新版本的Nokogiri Comtability problem had to reinstall the newest version of Nokogiri -
为什么我会收到ArgumentError - UTF-8中的字节序列无效?(Why do I get ArgumentError - invalid byte sequence in UTF-8?)[2022-02-23]
这来自CSV.open文档 : 您必须提供具有嵌入式编码指示符的模式,除非您的数据位于Encoding :: default_external()中。 CSV将检查底层IO对象的编码(由您传递的模式设置)以确定如何解析数据。 您可以提供第二个编码,以便在读取数据时对数据进行转码,就像正常调用IO :: open()一样。 例如,“rb:UTF-32BE:UTF-8”将从文件读取UTF-32BE数据,但在CSV解析之前将其转码为UTF-8。 这适用于CSV中用于打开文件的任何方法。 还可以从以下部分的文档开始 ... -
java.util.Properites类使用ISO 8859-1编码。 使用Ant 1.8.2进行测试时,以下工作正常。 build.xml文件
相关文章
更多- Don’t work. Be hated. Love someone.
- RabbitMQ Work模式消息队列
- Python IndentationError:expected an indented block的解决方案
- 关于如何参与到开源项目中《How To Succeed In Open Source ( In Ways You Haven't Considered Yet )》
- Hadoop HDFS Wrong FS: hdfs:/ expected file:///
- gui求jtapi高手T_T
- javascript replace 连续用两次的问题
- Memcached replace 替换已存在的 key命令
- webservice可不可以实现动态的返回类型:<T> List<T> getList(T a)
- add more solr core for switch deploy old new replace hot deploy
最新问答
更多- 您如何使用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)