[英]using curl commands in php
我一直很困惑如何在php中使用curl來運行這段代碼。
$ curl -F userfile=@Image_File_Name \
-F outputencoding="utf-8" \
-F outputformat="txt" \
http://Server_Address/cgi-bin/submit.cgi >result.txt
有人可以幫我嗎? 我嘗試了以下方法:
$cmd="curl -F userfile=$file_new \
-F outputencoding="utf-8" \
F outputformat=txt \
http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi >result.txt"
exec($cmd,$result);
echo $result;
但它不起作用。
謝謝!
您需要轉義字符串中的雙引號:
$cmd="curl -F userfile=$file_new \
-F outputencoding=\"utf-8\" \
F outputformat=\"txt\" \
http://maggie.ocrgrid.org/cgi-bin/weocr/ocr_scene.cgi >result.txt"
那應該工作。 exec
還以換行符分隔的數組形式返回其輸出。 所以echo $result;
只會打印“數組”。 您可能要回顯$ result [0];。 或考慮使用backticks
或passthru
。
我建議不要在單獨的shell中執行cURL,而是建議使用php cURL庫: http : //php.net/manual/en/book.curl.php
libcurl更適合您-它提供了在PHP中使用cURL所需的所有功能和錯誤處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.