递归读取文件,复制部分并附加到新文件?

时间:2017-03-23 18:07:36

标签: php

我正在尝试使用PHP迭代几个目录来读取所有相应的文件,并从文件中复制一段文本并附加到一个新的单独文件中。

文本位于,

之间
String httpsURL = "https://api.postmates.com/v1/customers/cus_xxxxxxx_yqV/delivery_quotes";
URL myurl = new URL(httpsURL);
HttpsURLConnection con = (HttpsURLConnection)myurl.openConnection();
con.setRequestMethod("POST");
con.setRequestProperty("Authorization", 
"Basic 3d458af1-4a7a-469e-a4d0-ba07cd94c333:" );
String postData = "pickup_address=" + 
    java.net.URLEncoder.encode("20  McAllister St, San Francisco, CA", "UTF-8") + 
    "&" + "dropoff_address=" + 
    java.net.URLEncoder.encode("101 Market St, San Francisco, CA", "UTF-8");

con.setDoOutput(true);
OutputStream os = con.getOutputStream();
os.write(postData.getBytes());

InputStream ins = con.getInputStream();
InputStreamReader isr = new InputStreamReader(ins);
BufferedReader in = new BufferedReader(isr);
String inputLine;
while ((inputLine = in.readLine()) != null) {
    System.out.println(inputLine);
}
in.close();

请问最好的方法是什么?

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

function copySection($sStartNeedle, $sEndNeedle, $sText)
{
    $sText = substr($sText, strpos($sText, $sStartNeedle) + strlen($sStartNeedle));
    $sText = substr($sText, 0, strpos($sText, $sEndNeedle));

    return( $sText );
}