从php中的字符串中删除转义序列 [英] remove escape sequences from string in php

查看:134
本文介绍了从php中的字符串中删除转义序列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用已经转义字符序列的mysqldump文件。我需要知道一个字符串的长度作为其数据库值,但转储中有转义字符,它将长度添加到字符串。



我已经使用了 stripslashes()它正确地解除单引号和双引号,但它没有不要触摸 \r\\\



我担心还有其他转义的字符序列,我不知道。有没有一个我可以使用的功能,会给我真正的长度的字符串,因为它将在数据库中?如果我必须构建自己的函数,还应该处理什么其他序列?

解决方案

strip c slashes()功能确实如此:

  stripcslashes( 'foo\r\\\
');


I'm working with a mysqldump file that has escaped character sequences. I need to know the length of a string as its database value, but the dump has escape characters in it, which add length to the string.

I've used stripslashes() which properly un-escapes single- and double-quotes, but it doesn't touch the \r\n.

I'm concerned there are other escaped character sequences in there that I'm not aware of. Is there a function I can use that will give me the true length of the string as it would be in the database? If I have to build my own function, what other sequences should it handle?

解决方案

The strip c slashes() function does exactly that:

stripcslashes('foo\r\n');

这篇关于从php中的字符串中删除转义序列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆