2011-07-13 20 views
0

データベーステーブルのsettings.iniファイルを作成するルーチンを作成しています。データベースのフィールド値から改行を削除します

DBに格納されているオプション値に改行が含まれていると、出力ファイルに問題があります。下記の設定「test_custom_css」のようなたとえば

、...

test_current_sort = asc 
test_custom_css = /*.blog ul li {margin-bottom:0;padding-bottom:0;} 

#facebook_like iframe {height:30px;} 

.footer ul li:last-child a {border:none;} 
*/ 
test_custom_footer = true 
test_custom_header = true 
test_friendlyURLS = 1 

私は改行を削除するには、以下のループ内で$ mySettings変数に適用することができますPHPフィルタはありますか?

function wpseTest() 
{ 
    $query = "SELECT option_name, option_value FROM wp_options where option_name like 'test|_%' escape '|' AND option_value > ''"; 
    global $wpdb; 
    $matches = $wpdb->get_results($query); 

    $mySettings = '[settings]\r\n'; 

    foreach ($matches as $result){ 
     $mySettings .= $result->option_name; 
     $mySettings .= ' = '; 
     $mySettings .= $result->option_value; //REMOVE LINE BREAKS HERE 
     $mySettings .= '\r\n'; 
    } 

    $mySettingsFileLocation = WP_PLUGIN_DIR.'/test/settings-backup.ini'; 
    $mySettingsFile = fopen($mySettingsFileLocation, 'w'); 
    fwrite($mySettingsFile, $mySettings); 
    fclose($mySettingsFile); 
} 

答えて

0
$x = preg_replace('/\r\n|\r|\n\r|\n/m', ' ', $x); 

すべての改行を削除します。

0
<?php 
$mySettings = str_replace("\r\n", "", $mySettings); 
?> 
関連する問題