我有一个在它的URL字符串,我想查找和替换用别的东西URL的可预测部分。
基本上,如何随机化的子域的选择。
例如, $file
包含: https://url.foo.com/w_Path/File.doc
我如何检查是否$file
包含url.foo.com
,如果是这样,则更换url.foo.com
与部分要么differentsubdomain.foo.com
或anotherplace.foo.com
或someotherplace.foo.com
?
输入:
$file = "https://url.foo.com/w_Path/SomeFile.ext";
$params['file'] = $file
所需的输出:
$file = "https://url.foo.com/w_Path/SomeFile.ext";
// list of subdomains = "differentsubdomain", "anotherplace", "someotherplace";
// find 'url.foo.com' part of $file and replace with random subdomain choice from list
// $file = "https://someotherplace.foo.com/w_Path/SomeFile.ext";
$params['file'] = $file