My objective for posting this blog is to tell how do we convert shell scripting code to php. In some cases we need to use php code instead of executing shell script. Therefore I am writing the blog which may help someone to understand how do we convert shell script to php code. I was facing issues while converting following shell script lines to the php. Following lines of code is using curl. It is posting property ids to the url getaroom api via shell.
Shell Script:
URL="https://availability.getaroom.com/api/1.1/room_availability?transaction_id=***&check_in=08/18/2015&check_out=08/19/2015&rooms=1&adults=2&cancellation_rules=1&api_key=**************&auth_token=*********************¤cy=AUD"
curl -k \ -w '\nHTTP STATUS: %{http_code}\n'\
-F "property_id[]=92cf91e5-9032-5e03-8d78-ff1e3af7d9d0" \
-F "property_id[]=6e6b2fbe-75c3-5896-aab0-6d809d6d4ac1" \
-F "property_id[]=c96d6baf-5d6c-564f-9cc4-7ed446e7785c" \
-X 'POST' "$URL"
Following is the alternative code for shell script in php. Above code can be used in shell script and following code can be used in php
Php Code:
$posturl="https://availability.getaroom.com/api/1.1/room_availability?transaction_id=***&check_in=08/18/2015&check_out=08/19/2015&rooms=1&adults=2&cancellation_rules=1&api_key=**************&auth_token=*********************¤cy=AUD";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$posturl);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,"property_id=1234567890");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$getaroomsearch = new SimpleXMLElement(curl_exec($ch));
curl_close ($ch);
Thanks for reading.
0 Comment(s)