Php 如何对包含正向斜杠的查询字符串进行编码?
我需要将路径作为参数传递给url,例如。 /Controller/Action/My Path但My Path包含正斜杠,例如/dir1/dir2/file.php 是否有任何方法可以将此路径作为单个参数传递,或者是否需要将路径分解为/Controller/Action/Param1/dir1/Param2/dir2/Param3/file.php。一些示例代码将不胜感激 蒂亚·以法莲参见: 所以你会这样做:Php 如何对包含正向斜杠的查询字符串进行编码?,php,zend-framework,url,Php,Zend Framework,Url,我需要将路径作为参数传递给url,例如。 /Controller/Action/My Path但My Path包含正斜杠,例如/dir1/dir2/file.php 是否有任何方法可以将此路径作为单个参数传递,或者是否需要将路径分解为/Controller/Action/Param1/dir1/Param2/dir2/Param3/file.php。一些示例代码将不胜感激 蒂亚·以法莲参见: 所以你会这样做: $param = url_encode("/this/parameter/file")
$param = url_encode("/this/parameter/file");
您可以使用url视图帮助器,例如:
echo $this->view->url(
array(
'controller' => 'somecontroller',
'action' => 'someaction',
'path'=>'/dir1/dir2/file.php')
);
这将导致:
public/somecontroller/someaction/path/%2Fdir1%2Fdir2%2Ffile.php
url视图帮助程序自动使用url_encode对您的参数进行编码(请参见其他anwser)。Embed in和yiou getEmbed in,您将获得../path//dir1/dir2/file.php