Jump to content

echo issue


adv

Recommended Posts

what i`m saying is in a for loop

 

its echoes likes this

[adv@localhost tmp]# php aaa
showing -> 0
showing -> 1
showing -> 2
showing -> 3
showing -> 4
showing -> 5
showing -> 6
showing -> 7
showing -> 8
showing -> 9
showing -> 10

 

 

 

and the thing is i want to show it just like this


[adv@localhost tmp]# php aaa
showing -> ascendent from 0 to 10 repeatedly

Link to comment
https://forums.phpfreaks.com/topic/233896-echo-issue/#findComment-1202334
Share on other sites

<?php
for($i=0;$i<=10;$i++){ // You have $i set to 0, going up to 10. (11 rows)
echo $i;
}

Output:

012345678910

 

<?php
$start = //your code here
$end = //your code here
$total_cnt  = //your code here
for($i = $start; $i <= $end;$i++){ // Now you have $i as a variable, and the end as a variable
// some code here
}

echo "Displaying $start to $end of $total_cnt rows.";

Output (assuming that start is 2, end is 17, and total count is 150:

Displaying 2 to 17 of 150 rows.

 

Link to comment
https://forums.phpfreaks.com/topic/233896-echo-issue/#findComment-1202369
Share on other sites

sorry maxudaskin but you understood me wrong :|

 

i dont want to display from a table some lines

i just want to show when i execute in linux

 

 

when i do something like this :

 
<?php


for($i=0;$i<=10000;$i++){

echo $i;
}

?>

 

i want to show like this

 

[adv@localhost tmp]# php aaa

showing -> ascendent from 0 to 10000

 

to show the increasing numbers in just one line

Link to comment
https://forums.phpfreaks.com/topic/233896-echo-issue/#findComment-1202381
Share on other sites

Oh I think I might get what you mean. Is it that you want to show:

 

showing -> ascendent from 0 to 10000

 

then show:

 

showing -> ascendent from 1 to 10000

 

on the same line of the command line output?

 

Might not be a good explanation but try this and see if it's right:

 

<?php

$start = 0;
$end = 1000;
$last_line_lemgth = 0;

echo 'showing -> ascendent from ';

for($i=$start;$i<=$end;$i++)
{
echo str_repeat("\x08", $last_line_lemgth); //backspace char to clear last line

echo "{$i} to {$end}";
sleep(1);// so can see it working
$last_line_lemgth = strlen("{$i} to {$end}");
}

?>

Link to comment
https://forums.phpfreaks.com/topic/233896-echo-issue/#findComment-1202443
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.