Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/267.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将%20替换为url中的-_Php - Fatal编程技术网

Php 如何将%20替换为url中的-

Php 如何将%20替换为url中的-,php,Php,我是php新手。我的问题是,我想用-替换url中的%20 <?php $test1='exmple.com/dp/id/om%20Joan'; $test1=str_replace('%20','-',$test1); echo $test1; 结果: $cleanUrl = 'www.somesite.com/in-here/'; url\u decode($yourURL),它将恢复空格和特殊字符以进行解码。您能给我一个示例吗code@teeyo%20是一个空格,因此它将被解码

我是php新手。我的问题是,我想用
-
替换url中的
%20

<?php

$test1='exmple.com/dp/id/om%20Joan';

$test1=str_replace('%20','-',$test1);
echo $test1;
结果:

$cleanUrl = 'www.somesite.com/in-here/';

url\u decode($yourURL)
,它将恢复空格和特殊字符以进行解码。您能给我一个示例吗code@teeyo
%20
是一个空格,因此它将被解码为空格,
-
将是
%2D
您能确认您想将
%20
转换为
-
,而不是空格吗?您能提供更多上下文吗?
$myUrl = 'www.somesite.com/in here/';

$cleanUrl = str_replace('/\\s/', '-', $myUrl);
$cleanUrl = 'www.somesite.com/in-here/';