Reputation: 23
I'm developing a system that works that way:
However, in one of the rows, the parameters are stored using line breaks, and I need that my system identify this line break, and the 'send' as new value.
Code:
foreach($rows as $row){
$ips = $row['dedicatedip'];
$ips2 = $row['assignedips'];
$status = $row['domainstatus'];
echo '<b>', $ips . ' -</b> '; echo "<input type='text' value="; echo consultaIP($ips); echo ">"; echo '<b> Status:'; if ($status==Active) { echo ' <span class="label active">Ativo</span></b><br><br>';} else { echo ' <span class="label pending">Desativado</span></b><br/><br/>';}
if ($ips2 != '') { echo '<b>', $ips2 . ' -</b> '; echo "<input type='text' value="; echo consultaIP($ips); echo ">"; echo '<b> Status:'; if ($status==Active) { echo ' <span class="label active">Ativo</span></b><br><br>';} else { echo ' <span class="label pending">Desativado</span></b><br/><br/>';} }
}
PS: function consultaIP is a function that lookups the IP reverse DNS.
The dedicatedip row have just one value stored, so it's ok. But the assigned IP's, have a buch, stored like this:
177.101.0.100
177.101.0.101
177.101.0.102
The problem is that the system need to create the input for each IP, and this is not happening (it's showing like this: 177.101.0.100 177.101.0.101 177.101.0.102).
Those values will not get back to the database, so this will not be problem. It'll be used in the POST form.
Edit:
I've added this line:
chars = explode("\n", $ips2);
And the array looks like that:
Array ( [0] => 177.101.229.92 [1] => 177.101.229.80 )
But, how can I use this array output in my foreach, and correctly populate the input?
Solved:
$chars = explode("\n", $ips2);
foreach($chars as $iplista){
if ($ips2 != '') { echo '<b>', $iplista . ' -</b> '; echo "<input type='text' value="; echo consultaIP($ips); echo ">"; echo '<b> Status:'; if ($status==Active) { echo ' <span class="label active">Ativo</span></b><br><br>';} else { echo ' <span class="label pending">Desativado</span></b><br/><br/>';} }
}
Upvotes: 2
Views: 281
Reputation: 6702
If I do understand correct, you want an array of IP addresses to process on every single IP?
You can use the explode function to split the string, e.g. on newline char "\n"
. If you don't know the newline sequence (\r, \n, or \r\n) or the input could vary, you could use preg_split instead to split by a regular expression, e.g. \s
for all whitespaces or (\r|\n|\r\n)
for system independent line break.
Upvotes: 2