如何编码包含正斜杠的查询字符串?

时间:2011-07-21 13:56:49

标签: php zend-framework url

我需要将路径作为参数传递给网址,例如 / Controller / Action / My-Path但My-Path包含正斜杠,例如/dir1/dir2/file.php 有没有办法将此路径作为单个参数传递,或者我需要将路径分解为/Controller/Action/Param1/dir1/Param2/dir2/Param3/file.php。一些示例代码将不胜感激

TIA Ephraim

2 个答案:

答案 0 :(得分:4)

您可以使用网址视图助手,例如:

    echo $this->view->url(
            array(
            'controller' => 'somecontroller',   
            'action' => 'someaction',    
            'path'=>'/dir1/dir2/file.php')
            );

这将导致:

public/somecontroller/someaction/path/%2Fdir1%2Fdir2%2Ffile.php

url view helper自动使用url_encode对参数进行编码(参见其他anwser)。

答案 1 :(得分:0)

请参阅:http://ar2.php.net/url_encode

所以你会这样做:

$param = url_encode("/this/parameter/file");