Номериране на редове.

C++ JAVA
Post Reply
User avatar
ArchangelS
Много Редовен
Много Редовен
Posts: 1870
Joined: Sun Mar 16, 2008 9:13 am
Answers: 41

Номериране на редове.

Post by ArchangelS » Tue Jan 06, 2009 7:14 am

Как мога да задам чрез пхп .. на секи нов ред да се номерира. ?

User avatar
emagi
Шаман
Шаман
Posts: 6476
Joined: Fri Dec 07, 2007 3:24 pm
Answers: 1032

Post by emagi » Tue Jan 06, 2009 7:28 am

Ето един вариант:

Code: Select all

<?php
if&#40;isset&#40;$_POST&#91;'send'&#93;&#41;&#41;&#123;
	$text = $_POST&#91;'text'&#93;;
	$text = explode&#40;"\n", $text&#41;;
	for&#40;$i=0; $i<sizeof&#40;$text&#41;; $i++&#41;&#123;
		echo &#40;$i+1&#41;.".".$text&#91;$i&#93;."<br />";
	&#125;
&#125;
else &#123;
	?>
	<form method="POST" action="">
	<textarea name="text" cols="10" rows="10"></textarea><br />
	<input type="submit" name="send" />
	</form>
	<?php
&#125;

User avatar
emagi
Шаман
Шаман
Posts: 6476
Joined: Fri Dec 07, 2007 3:24 pm
Answers: 1032

Post by emagi » Tue Jan 06, 2009 7:30 am

Още един вариант:

Code: Select all

<?php
if&#40;isset&#40;$_POST&#91;'send'&#93;&#41;&#41;&#123;
	$text = $_POST&#91;'text'&#93;;
	$text = explode&#40;"\n", $text&#41;;
	$i=0;
	while&#40;$i<sizeof&#40;$text&#41;&#41;&#123;
		echo &#40;$i+1&#41;.".".$text&#91;$i&#93;."<br />";
		$i++;
	&#125;
&#125;
else &#123;
	?>
	<form method="POST" action="">
	<textarea name="text" cols="10" rows="10"></textarea><br />
	<input type="submit" name="send" />
	</form>
	<?php
&#125;

User avatar
deam0n
Web-tourist
Web-tourist
Posts: 3036
Joined: Sat Oct 01, 2005 4:33 pm
Answers: 204
Location: Шопландия
Contact:

Post by deam0n » Tue Jan 06, 2009 7:53 am

Много голяма разлика между двата скрипта :)

User avatar
emagi
Шаман
Шаман
Posts: 6476
Joined: Fri Dec 07, 2007 3:24 pm
Answers: 1032

Post by emagi » Tue Jan 06, 2009 8:05 am

deam0n wrote:Много голяма разлика между двата скрипта :)

Вчера стана дума, че цикъла for бил най-бавен, а аз предпочитам него да ползвам, затова дадох и двата варианта!КОй от двата начина ще ползва не знам!

User avatar
bafitu
Много Редовен
Много Редовен
Posts: 1509
Joined: Mon Dec 12, 2005 9:12 am
Answers: 102
Location: Somewhere around nothing..

Post by bafitu » Tue Jan 06, 2009 8:21 am

//off
sizeof , го дефинирайте в отделна променлива преди циклите
т.е. for($i=0; $i<sizeof($text); $i++) ->$sizeof = sizeof($text); for($i=0; $i<$sizeof; $i++)
//end off

User avatar
ArchangelS
Много Редовен
Много Редовен
Posts: 1870
Joined: Sun Mar 16, 2008 9:13 am
Answers: 41

Post by ArchangelS » Tue Jan 06, 2009 8:41 am

+ 1 emagi :)

Post Reply