2016-12-03 7 views
1

私は1month.sshという名前のテキストファイルがあります。警告:構文エラー、予期しないBOOL_TRUE

Host: m-sg5.portssh.com 
Username: portssh.com-myuser 
Password: mypass 
Port: 443 
Info: Your Account will expire on 02-January-2017 

を私は、そのファイルに基づいて配列を作成しようとしています:

$infossh = parse_ini_string(preg_replace('/^([^:]+): (.+)$/m','$1 = $2',file_get_contents('/home/ab/gconf/'.$_POST['account']))); 

$_POST['account']1month.sshを指し、 。私の目標は、私は、配列をエコーする場合、各値は次のようにあるべきである。

$infossh['Host'] = "m-sg5.portssh.com" 
$infossh['Username'] = "portssh.com-myuser" 
$infossh['Password'] = "mypass" 
$infossh['Port'] = "443" 
$infossh['Info'] = "Your Account will expire on 02-January-2017" 

しかし、代わりにそのコードで、私は次のエラーを取得する:

Warning: syntax error, unexpected BOOL_TRUE in Unknown on line 5 in /www/ssh.php on line 218 

は、どのように私はこの問題を解決することができますか?

ADDITIONAL INFO:

私は別のファイルsgdo.sshあります

Host: x-sgdo19.serverip.co 
Username: fastssh.com-myuser 
Password: mypass 
Port: 443 
Info: Date Expired : 10-December-2016 

をしかし、私は、このファイルでエラーを取得していない私は1month.ssh

+0

同じファイルに複数の「ホスト」がありますか? – Perumal

+0

@ Perumal93 1つのsgdo.sshと1month.sshだけが2つの異なるファイルです。 – hillz

+0

同じファイル内の各ホストの5つの行が繰り返されることを意味しますか?あなたは私のポイントを持っていますか? – Perumal

答えて

1
Host: m-sg5.portssh.com 
Username: portssh.com-myuser 
Password: mypass 
Port: 443 
Info: Your Account will expire on 02-January-2017 

を開くと、エラーは発生しここでは、Infoの値を引用符で囲む必要があります。

EDIT

$infossh = file('1month.ssh', FILE_IGNORE_NEW_LINES); 
$new_infossh = []; 

array_walk($infossh, function($element, $index) { 
    global $new_infossh; 
    $element_temp = explode(': ', $element); 
    $new_infossh[$element_temp[0]] = $element_temp[1]; 
}); 

var_dump($new_infossh); 

私はより単純化されたものに上記の私のコードを変更しました。

$infossh = file('1month.ssh', FILE_IGNORE_NEW_LINES); 
$new_infossh = []; 

foreach($infossh as $value) { 
    $value_arr = explode(': ', $value); 
    $new_infossh[$value_arr[0]] = $value_arr[1]; 
} 

var_dump($new_infossh); 

私の見解では、これらは正規表現を使用せずに作成できる2つの方法です。それが動作することを願って!

+0

それはそれを修正しましたが、これよりも良い方法がありますか? – hillz

+0

うん。しかし、正規表現はありません。それに行きたいですか? – Perumal

+0

正規表現なしでコードを書くことができますか? – hillz

関連する問題