【问题标题】:Decoding ascii in url php在url php中解码ascii
【发布时间】:2019-03-25 20:13:17
【问题描述】:

我尝试在我的 url 站点中使用 ascii 字母,但我不知道我在我的 url 中使用了什么 ascii 字母(è、é、à、ect..)。我尝试使用 urlencode\urldecode 但是当我使用 ascii 字母时我无法查看我的页面。我不知道什么可以解决这个问题。 你能帮我举个例子吗?

function my_url($offer) {
$dd = url_title($offer->number." ".$offer->number,"-",true);
return site_url("siteweb\view".$offer->number."/".urlencode($dd));

我的问题在于“urlencode($dd)”

更新

    function my_url($offer) {
$dd = url_title($offer->number." ".$offer->number,"-",true);
$ddd= rawurldecode($ddd)
return site_url("siteweb\view".$offer->number."/".htmlspecialchars($ddd));

【问题讨论】:

  • 我认为你的意思是非 ascii 字符...
  • 您在哪里尝试使用该 URL。如果您在 URL 上下文中使用 URL,例如链接,那么olè 编码为ol%E3%A9 是正确的。但是,如果您向用户显示 URL,则应该是 rawurldecode-ed,然后在显示之前通过 htmlspecialchars
  • 我试了一下,但我再也看不到我的网址了:S 我先使用 urldecode,然后使用 htmentities
  • 我先使用 htmlspecialchars 还是 rawurldecode ?
  • rawurldecode 先是 htmlspecialchars,但只有当您打算将其显示为可读文本时才应该这样做!

标签: php ascii decode


【解决方案1】:

我想你要找的是htmlentities

"htmlentities — 将所有适用的字符转换为 HTML 实体"

【讨论】:

  • 这对 URL 的上下文有何帮助?
  • 您也应该在 url 中使用 htmlentities。转到我发布的链接并查看示例 #2。 php.net/manual/en/function.urlencode.php
  • 显然您当时没有阅读手册,直接来自示例 #2: echo '';
  • 但是这样我不能在我的网址中使用(例如:-olè),因为它变成了:mysite.it/ol%E3%A9 我想使用-olè
  • 你需要在尝试显示之前对其进行解码。
猜你喜欢
  • 1970-01-01
  • 2021-07-28
  • 2014-03-21
  • 2019-10-21
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 2012-11-27
相关资源
最近更新 更多