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 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看