使用php和javascript进行URL编码?

使用php和javascript进行URL编码?,php,javascript,url,symfony1,Php,Javascript,Url,Symfony1,我在现有的项目上工作。在某些情况下,它的实施效果很差 例如,我在一个操作中发现以下代码: <?php echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".$this->username';</script>"; ?> 它将其转换为 UnestÃ¥l 并返回一个服务器错误 你知道怎么解决这个问题吗 谢谢您可以尝试使用PHP

我在现有的项目上工作。在某些情况下,它的实施效果很差

例如,我在一个操作中发现以下代码:

<?php
    echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".$this->username';</script>"; 
?>
它将其转换为

Unestål
并返回一个服务器错误

你知道怎么解决这个问题吗


谢谢

您可以尝试使用PHP
urlencode
函数:

<?php
    echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".urlencode($this->username). "';</script>"; 
?>

当它被重定向时,我在浏览器地址栏中看到了转换后的代码。我只是用
window.location='Uneståhl
尝试了这种方法,但浏览器没有更改值。尝试使用IE9和Chrome。您尝试了什么浏览器?与您的问题无关:这看起来像是试图用JavaScript模拟重定向。您应该使用正确的重定向-尤其是因为您使用的是PHP。所以可能是PHP问题,在某个地方转换它。这看起来像是字符集不匹配的问题。“转换”版本看起来像ISO-8859-1中表示的UTF-8。已修复,但它使用的是
urlencode()
url\u encode()
给了我函数未找到的错误。你说得对。对不起,弄错了。我会更新答案。
<?php
    echo "<script>window.location='/".$this->getRequestParameter("culture")."/profile/".urlencode($this->username). "';</script>"; 
?>