I have this code
$cl_posturl = "https://post.craigslist.org/".str_replace('"','',$result[FORM][0][ACTION]);
echo $cl_posturl."<br>\n";
It if returning
post.craigslist.org//sdo/S/ctd/csd/x/ 9FMALgak4Td10Bol/XRk68
it use to return
post.craigslist.org//sdo/S/ctd/csd/x/
how can I modify the code to return it without those 2 last paths
Hey broken this into a few steps for easy reading, but it can be condensed into a single call once you understand it.
$initialString = '/sdo/S/ctd/csd/x/9FMALgak4Td10Bol/XRk68';
$removeOneLevel = substr($initialString, 0, strrpos($initialString, '/'));
$removeSecondLevel = substr($removeOneLevel, 0, strrpos($removeOneLevel, '/'));
$finalUrl = "https://post.craigslist.org".str_replace('"','', $removeSecondLevel);
echo $finalUrl . "\n";
Hope that helps.
Why did the value of $result[FORM][0][ACTION]
change from
/sdo/S/ctd/csd/x/
to
/sdo/S/ctd/csd/x/9FMALgak4Td10Bol/XRk68
?
I would first understand why that happened.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.