我需要在文本文檔中找到*.jpg
名稱。例如,我有一個文件夾與圖片file1
,file2
,file3
和一個文本文件與file1
,file
,file3
每個在一個新的行。我需要在每個*.jpg
附近寫入文件中的文本,但首先我需要在文本文檔中找到相應的行。PHP搜索內部加載的文本文件,轉換爲數組
<?php
$arrayF = explode("\n", file_get_contents('myTxt.txt'));
// arrayF should the the array with each text line from the txt file.
while(($file = readdir($opendir)) !== FALSE)
{
if($file!="." && $file!="..")
{
$string=$file;
$arrayS = explode('.', $string);//get the name only without .jpg extension
$search=$arrayS[0];
$key = array_search($search, $arrayF);
echo $key;
}
所以,你必須與圖像文件名(1名= 1行文件? ),你想顯示它們沒有擴展名? 1.請添加一個示例,瞭解文本文件的外觀和預期輸出結果 – Rizier123
問題是什麼? – maalls
我得到例如picture2.jpg多種JPG,而文本文件看起來像這樣 圖片1 dimension_30x30 圖片2 dimension_40x50 圖片3 dimension_10x10(圖片名稱和尺寸在每個單獨的行)。 所以我需要找到picture2.jpg我應該在圖片附近添加什麼尺寸。並且我嘗試搜索該行,然後行+ 1是正確的答案。 – oma