tags:

views:

79

answers:

2

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

A: 

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.

Drew Hoskins
[FORM] => Array ( [0] => Array ( [ID] => "postingForm" [ACTION] => "/sdo/S/ctd/csd/x/vayNgFunjY5mPr9C/iNp0B" [METHOD] => "post" [ENCTYPE] => "multipart/form-data" ) )The Action value is now returning that additional data. but when posting to it we get a 404
Aaron R
try: $cl_posturl = "post.craigslist.org/".$result[FORM][0][ACTION]; echo $cl_posturl."<br>\n"; and post it here
inakiabt
+1  A: 

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.

NWCoder
Oh BTW, I used $initialString rather than $result[FORM][0][ACTION] so that I could test from the command line.
NWCoder
thanks that worked.
Aaron R