doulao3905 2016-02-28 03:24
浏览 38
已采纳

如何从具有空格的数据库中调用变量

I am using php $_GET function to call parameters from the database. And these perameters are usually variable within the url.

E.g. http://localhost:8080/series/dynamics/admin/cleanURL/Apple, where Apple is the variable from the database.

This works fine as long as GET function doesn't encounter a space, however in a real life situation I will have some variable such as "Green Apple" "Red Apple" etc..and URL will like,

http://localhost:8080/series/dynamics/admin/cleanURL/Green%20Apple and in that case I am getting 404 The requested URL was not found on this server error.

What I would like to achieve is to be able to conver whitespace into hyphen or +. I have done it through strreplace or urlencode() however the problem is I am still not able to get rid 404 error.

Just incase if it has anything to do with htaccess below is my code

 Options +MultiViews 
 Rewriteengine on
 RewriteBase /series/dynamics/admin/cleanURL/

 RewriteCond %{REQUEST_FILENAME} !-f [OR]
 RewriteCond %{REQUEST_FILENAME} !-d

 RewriteCond %{THE_REQUEST} /series/dynamics/admin/cleanURL/(\S*)\s [NC]

 Rewriterule ^(\w+)/?$ index.php?product=$1 [L,QSA]
 RewriteRule ^series/dynamics/admin/cleanURL/(.*)$ /$1 [L,NC,R]

 #rewrite group and subgroup e.g. http://.../value1/value2/
 Rewriterule ^([a-zA-Z0-9]+(.*)+)/([^/]+(.*)+)/?$ index.php?product=$1&subgroup=$2 [L,NC,QSA]
  • 写回答

1条回答 默认 最新

  • dongwan0574 2016-02-28 15:00
    关注

    a better question is why are you using folder structures that have whitespace? I'd just change the name of the files to be something like Green_Apple and your problem is fixed. It's better practices.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛