F
F
fokin_nikolay19892016-04-21 12:51:33
PHP
fokin_nikolay1989, 2016-04-21 12:51:33

Variable substitution in a cell?

I have php code

<?php
# Путь к файлу
$file_name = "set.txt";

# Считываем информацию по строкам
$data = file( $file_name );
$i = 1;


echo '<table border="1">';
echo	   ' <tr>
        <th>№</th>
        <th>Название</th>
        <th>Уровень</th>
        <th>Очки</th>
        <th>Очки</th>
        <th>Очки</th>
        <th>Очки</th>
        <th>Очки</th>
         <th>Очки</th>
        </tr>';


# В цикле обходим массив данных
foreach( $data as $value ):

# Разбиваем строку по |
$value = explode( "|", $value );

echo '<tr>';


{
echo '<td>' . $i++ . '</td>';
echo '<td>' . $value[0] . '</td>';
echo '<td>' . $value[1] . '</td>';
echo '<td>' . $value[2] . '</td>';
echo '<td>' . $value[3] . '</td>';
echo '<td>' . $value[4] . '</td>';
echo '<td>' . $value[5] . '</td>';
echo '<td>' . $value[6] . '</td>';
echo '<td>' . $value[7] . '</td>';
echo '</tr>';
}

endforeach;

echo '</table>';
?>

how can I insert the result of such an operation into a specific cell
<?php $host="192.168.1..1"; exec("ping -c 1 " . $host, $output, $result); if ($result == 0)       echo "<img src='/set/img/ok.png'  width='40' height='40'  >"; else echo "<img src='/set/img/no.png'  width='40' height='40' ";?>

It's just that the problem is that the table construction is taken from the data from the .txt file

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Shtinov, 2016-04-28
@delimer

$custom_data = '';
$host="192.168.1..1"; 
exec("ping -c 1 " . $host, $output, $result);
if ($result == 0) $custom_data =  "<img src='/set/img/ok.png'  width='40' height='40'  >"; else $custom_data = "<img src='/set/img/no.png'  width='40' height='40' ";

foreach( $data as $value ):

# Разбиваем строку по |
$value = explode( "|", $value );

echo '<tr>';


{
echo '<td>' . $i++ . '</td>';
echo '<td>' . $value[0] . '</td>';
echo '<td>' . $value[1] . '</td>';
echo '<td>' . $value[2] . '</td>';
if($i == 4 /* 4 строка*/) $value[3] = $custom_data;
echo '<td>' . $value[3] . '</td>';
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question