php特殊字符问题

发布于 2024-09-30 07:26:00 字数 842 浏览 2 评论 0原文

我的脚本中的特殊字符有问题:

这是我到目前为止所遇到的问题:

$curlstrip = explode("&", $data);
$filename = substr(htmlEntities($curlstrip[5]), 2);

如果 $data 包含任何特殊字符,例如 '是',那么我只得到第一部分,而不是得到我需要的字符串块。 更详细的示例:

$data = "12er&sdsretdgsd&file=Chris ' 19 &blabla"

脚本会将 Chris 之后的 ' 读取为 ' ,并且 $curlstrip[5] 将具有不同的值。

希望是足够明确的。

LE。按照这个例子:

$data = "12er&sdsretdgsd&file=Chris ' 19 &blabla"
$curlstrip = explode("&", $data);
$curlstrip[0] = '12er';
$curlstrip[1] = 'sdsretdgsd';

但是

$curlstrip[2] = 'file=Chris' instead of 'file=Chris ' 19'

那是因为 ' 被读作

'

Thx,

Cristian。

I am having a problem with the special characters in my script:

This is what I have so far:

$curlstrip = explode("&", $data);
$filename = substr(htmlEntities($curlstrip[5]), 2);

and if $data contains any special charaters like ' which is ', then instead of getting the chunk of string that I need, I get only the first part.
A more detailed example:

$data = "12er&sdsretdgsd&file=Chris ' 19 &blabla"

the script will read the ' after Chris as ' and $curlstrip[5] will have a different value.

Hope is clear enough.

LE. Following this example:

$data = "12er&sdsretdgsd&file=Chris ' 19 &blabla"
$curlstrip = explode("&", $data);
$curlstrip[0] = '12er';
$curlstrip[1] = 'sdsretdgsd';

but

$curlstrip[2] = 'file=Chris' instead of 'file=Chris ' 19'

and that is because the ' is being read as

'

Thx,

Cristian.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-10-07 07:26:00

尝试:

$curlstrip = explode("&", html_entity_decode($data));
$filename = substr(htmlEntities($curlstrip[5]), 2);

由于给定提供的代码,我无法复制您的错误,因此我有一种预感 - 尝试:

$data=str_replace("'","'", $data);
$curlstrip = explode("&", html_entity_decode($data));
$filename = substr(htmlEntities($curlstrip[5]), 2);

如果出于某种原因,您有 && (两个&符号)在 $data 中彼此相邻出现,它将干扰爆炸功能。

Try:

$curlstrip = explode("&", html_entity_decode($data));
$filename = substr(htmlEntities($curlstrip[5]), 2);

As I cant replicate your error given the code supplied, I have a hunch- try:

$data=str_replace("'","'", $data);
$curlstrip = explode("&", html_entity_decode($data));
$filename = substr(htmlEntities($curlstrip[5]), 2);

If, for whatever reason, you have && (two ampersands) occurring in $data next to one another, it will interfere with the explode function.

清旖 2024-10-07 07:26:00

让 htmlentities 成为您对数据调用的最后一个对象。

$filename = htmlentities(substr($curlstrip[5], 2));

除此之外,还有一些函数可以处理您正在做的事情。 parse_str 将从查询字符串创建一个数组。 parse_url 可用于从 URL 中提取查询字符串。

Make htmlentities the last thing you call on the data.

$filename = htmlentities(substr($curlstrip[5], 2));

Aside from that there are functions to deal with what you're doing. parse_str will create an array from a query string. parse_url can be used to extract the query string from a url.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文