php:在 url 中最后一个斜杠之前插入字符串

如何在url中的最后一个斜杠后添加字符串?

current url: https://example.org/gallery/images/my-image.jpg

我需要将“thumbs/”字符添加到最后一个斜杠中

函数或 php 代码必须更改地址,如下所示

https://example.org/gallery/images/thumbs/my-image.jpg

请指导我


杨魅力
浏览 172回答 2
2回答

浮云间

有很多方法。尝试使用 URL 和路径函数并替换:$string = str_replace($dir=dirname(parse_url($string, PHP_URL_PATH)),                      "$dir/thumbs",                      $string);或字符串函数:$string = str_replace($s=strrchr($string, '/'), "/thumbs$s", $string);

温温酱

连接字符串。<?php&nbsp; &nbsp; &nbsp;$addString = "thumbs/";&nbsp; &nbsp; &nbsp;$newURL = "https://example.org/gallery/images/" . $addString . "my-image.jpg";&nbsp; &nbsp; &nbsp;echo $newURL;
打开App,查看更多内容
随时随地看视频慕课网APP