PHP:Preg-replace 中的 Rawurlencode
while($row = mysql_fetch_array($result)){ $搜索=''。 $row['searchquery'];
echo '' ...
但是如果有人输入 äöü,它不会显示字母 - 使用 rawurlencode 这是可能的,但我想用 pregreplace 删除空格并用 + 替换它,
这可能吗?
while($row = mysql_fetch_array($result)){
$search = '' . $row['searchquery'];
echo '' ...
but if someone types in äöü, it doesnt show the letters - with rawurlencode thats possible, but I want to remove the blank spaces with pregreplace and replace it with +
is that possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的问题的答案是使用实际上可以处理 UTF-8 字符串的正则表达式函数。
您还可以对
preg
函数使用/u
修饰符:这看起来更好,但您应该小心。我现在已经尝试过,它可以很好地输出您的字符,但我注意到它删除了我作为输入给出的其他一些 UTF-8 字符 (ăşţ)。
zaf 是对的,有更简单的方法可以做到这一点:)。
The answer to your question would be to use a regular expression function that can actually handle UTF-8 strings.
You could also use the
/u
modifier for thepreg
functions:This seems better, but you should be careful. I've tried it now, and it outputs your characters fine, but I noticed it stripped out some other UTF-8 characters I've given it as input (ăşţ).
zaf is right, there are easier ways to do this :).
您对 str_replace 函数有异议吗?如果没有,那么您可以将其与 rawurlencode 一起使用。这会更简单、更快。
Do you have an objection to the str_replace function? If not then you can use it with rawurlencode. It would be a lot simpler and faster.