I've this URL:
https://example.com/[photo-s]/photo.jpg
Sometimes the part between []
changes.
How in PHP, can I replace this part with another thing ?
Example:
preg_replace('photo-[a-z]', 'newphotopath', 'photo-s');
I've this URL:
https://example.com/[photo-s]/photo.jpg
Sometimes the part between []
changes.
How in PHP, can I replace this part with another thing ?
Example:
preg_replace('photo-[a-z]', 'newphotopath', 'photo-s');
$url = 'https://example.com/[photo-s]/photo.jpg';
preg_replace('~\[(.*?)\]~', 'something_new', $url);
->
https://example.com/something_new/photo.jpg
If you mean to replace everything between .com/
and the following /
regardless of having brackets or not you could use:
preg_replace('~.com\/(.*?)\/~', '.com/something_new/', $url)
->
https://example.com/something_new/photo.jpg