I have a string with a URL in it and I wish to find and replace a predictable part of the URL with something else.
Basically, how to randomise a choice of subdomain.
For example, $file contains: https://url.foo.com/w_Path/File.doc how do I check if $file contains url.foo.com, and if so, replace the url.foo.com portion with either differentsubdomain.foo.com or anotherplace.foo.com or someotherplace.foo.com?
Input:
$file = "https://url.foo.com/w_Path/SomeFile.ext";
$params['file'] = $file
Desired output:
$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