Хорошо, чтение файла с использованием file_get_contents
и удаление <?php
, <?
и/или любых тегов ?>
, но я также хочу удалить все разрывы строк в файле. Как я могу этого добиться?
Например такой файл:
<?php
$txt['dpmod_testing'] = 'Testing';
$txt['dpmodtitle_testing'] = 'My Testing Module';
$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';
$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';
?>
Должно вернуть это:
$txt['dpmod_testing'] = 'Testing';
$txt['dpmodtitle_testing'] = 'My Testing Module';
$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';
$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';
Но вместо этого я записываю это в файл при использовании file_put_contents
:
$txt['dpmod_testing'] = 'Testing';
$txt['dpmodtitle_testing'] = 'My Testing Module';
$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';
$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';
С 2 разрывами строк сверху и 2 разрывами строк также снизу. Как я могу удалить все эти разрывы строк?
Вот preg_replace, который я использую для удаления тегов php из файла, но как это можно изменить, чтобы сохранить файл таким, какой он есть, и удалить все разрывы строк?
preg_replace(array('/<\?php/s', '/\?>/s', '/<\?/s'), array('', '', ''), $str);
Спасибо, парни :)
$str
? - person powtac   schedule 08.09.2011file_get_contents
для получения$str
из файла. - person SoLoGHoST   schedule 08.09.2011