Answer the question
In order to leave comments, you need to log in
How to output data from PHP array to HTML tag and attribute?
There is an array.txt file with names and links to pictures of conditional categories
/catalog/view/theme/default/icons/icons-catalog/id1.svg Химия для бассейнов
/catalog/view/theme/default/icons/icons-catalog/id2.svg Фильтры для бассейнов
/catalog/view/theme/default/icons/icons-catalog/id3.svg Насосы
/catalog/view/theme/default/icons/icons-catalog/id4.svg Дозирующее оборудование
<?php
$peremennaya = file("array.txt");
print_r($peremennaya);
?>
Array
(
[0] => /catalog/view/theme/default/icons/icons-catalog/id1.svg Химия для бассейнов
[1] => /catalog/view/theme/default/icons/icons-catalog/id2.svg Фильтры для бассейнов
[2] => /catalog/view/theme/default/icons/icons-catalog/id3.svg Насосы
[3] => /catalog/view/theme/default/icons/icons-catalog/id4.svg Дозирующее оборудование
)
<div class="_30CWHKH _3eXsdaG" str="1">
<div class="_1FmS6_e">
<img alt="Химия для бассейнов" src=" ВОТ СЮДА " /></div>
<a class="o0XE4_n" href="#">
<h2 class="_2PmikUJ" txt="1">И ТУТ</h2>
<div data-dy="menu-item-tag"></div>
</a>
</div>
<div class="_30CWHKH _3eXsdaG" str="2">
<div class="_1FmS6_e"><img alt="Фильтры для бассейнов" src="ВОТ СЮДА" /></div>
<a class="o0XE4_n" href="#">
<h2 class="_2PmikUJ" txt="2">И ТУТ</h2>
<div data-dy="menu-item-tag"></div>
</a>
</div>
Answer the question
In order to leave comments, you need to log in
a little working g..code
$arr=[
'/catalog/id1.svg Химия для бассейнов',
'/catalog/id2.svg Бла бла бла',
];
$data = [];
foreach($arr as $link) {
$split = explode(' ',$link);
$path = array_shift($split);
$name = implode(' ',$split);
$data[] = [
'path'=>$path,
'name'=>$name
];
}
print_r($data);
<?php foreach ($data as $link);?>
<div class="_30CWHKH _3eXsdaG" str="2">
<div class="_1FmS6_e"><img alt="Фильтры для бассейнов" src="<?php echo $link['path']; ?>" /></div>
<a class="o0XE4_n" href="#">
<h2 class="_2PmikUJ" txt="2"><?php echo $link['name']; ?></h2>
<div data-dy="menu-item-tag"></div>
</a>
</div>
<? endforeach;?>
<?php
$peremennaya = file("array.txt");
for ( $x = 0; $x < count( $peremennaya ); $x++ ) {
$n = $x + 1;
list( $src, $h2 ) = explode( ' ', $peremennaya[$x] );
echo '
<div class="_30CWHKH _3eXsdaG" str="' . $n . '">
<div class="_1FmS6_e">
<img alt="Химия для бассейнов" src="' . $src . '" />
</div>
<a class="o0XE4_n" href="#">
<h2 class="_2PmikUJ" txt="' . $n . '">' . $h2 . '</h2>
<div data-dy="menu-item-tag"></div>
</a>
</div>
';
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question