Please tell me there is a txt file. The file has data - html tags ( <p>Текст</p><a>Ссылка</a> ). There is also a select site:

 <select> <option>...</option> <option>...</option> <option>...</option> <option>...</option> </select> 

It is necessary that the tags from the file are entered in select Like this:

 <select> <option><p>Текст</p></option> <option><a>Ссылка</a></option> </select> 

Help me please.

  • Sample file in the studio - EatMyDust
  • @EatMyDust <p> Text </ p> <a> Link </a> - Vladislav Samokhin

2 answers 2

Something like this (if I understand you correctly):

 //Получаем содержимое файла в виде массива $content = file('text.txt'); //Перебираем все элементы массива в цикле foreach ($content as $string) { $string = explode("<a>", $string); echo '<option>' . $string[0] . '</option>'; } 
     <? //open file $file = file("1.txt"); //init array $arOptions = array(); //Read the file row by row foreach($file as $key => $row) { //get text preg_match("#<p>(.*)</p>#", $row, $text); //get links preg_match("#<a>(.*)</a>#", $row, $link); //put data to array $arOptions[$key]['text'] = $text[1]; $arOptions[$key]['link'] = $link[1]; } ?> <select> <? foreach($arOptions as $row): ?> <option><?=$row['text'];?></option> <option><?=$row['link'];?></option> <? endforeach; ?> </select>