将字符串添加到页面url


Add string to page url

例如,这是原始链接。http://localhost/myhouse/homes-for-sale-details/6200-SAN-VICENTE-BOULEVARD-LOS-ANGELES-CA-90048/OC16023911/306/

我想在"/待售房屋详细信息/"网址上添加"已售出"。

所以它看起来是这样的,需要转到这个链接。http://localhost/myhouse/homes-for-sale-sold-details/6200-SAN-VICENTE-BOULEVARD-LOS-ANGELES-CA-90048/OC16023911/306/

URL的一部分将用"已售出"一词链接:/待售房屋已售出详细信息/

// store url in variable
url = 'http://localhost/myhouse/homes-for-sale-details/6200-SAN-VICENTE-BOULEVARD-LOS-ANGELES-CA-90048/OC16023911/306/';
// get url with replace 
new_url = url.replace("homes-for-sale-details", "homes-for-sale-sold-details");
// store url in variable
$url = 'http://localhost/myhouse/homes-for-sale-details/6200-SAN-VICENTE-BOULEVARD-LOS-ANGELES-CA-90048/OC16023911/306/';
echo str_replace("homes-for-sale-details","homes-for-sale-sold-details",$url);

使用此代码,它将起作用。