PDA

View Full Version : PHP to .txt



Dromenail
13-09-2009, 01:55 PM
If I had the time I could write this script myself but I am looking for a way to create a .txt file with 4 digit numbers in it. however the numbers are all dynamically created. It would need every single 4 digit number there is.

Moved by Jamesy (Forum Moderator): From "Technology Discussion" - Please post in the correct forum in future.

Trinity
13-09-2009, 03:09 PM
So you want a .txt file with every number from 1000-9999 (or 0000-9999, whatever)?


If I had the time I could write this script myself

It would have taken less time to write the script than it took to create this thread.

Dromenail
14-09-2009, 02:58 PM
from 0000 and every other combination upwards.

BoyBetterKnow
14-09-2009, 07:36 PM
It would have taken less time to write the script than it took to create this thread.

Why didn't you help him then instead of just moaning?

Txt file:
http://www.zshare.net/download/65565576dca3208c/

PHP File:


<?php

$startNumber = 0000;

while ($startNumber <= 9999){

if (strlen($startNumber) == 1){

echo '000'.$startNumber.'<br>';

}else if (strlen($startNumber) == 2){

echo '00'.$startNumber.'<br>';

}else if(strlen($startNumber) == 3){

echo '0'.$startNumber.'<br>';

}else{

echo $startNumber.'<br>';

}


$startNumber++;

}
?>

The php script is awful but it works. I couldn't remember the way to number format. Oh well, I wrote it super quick and nobody else offered to help so umm there you go I suppose.

Invent
14-09-2009, 07:45 PM
<?php

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

echo $i . '<br />';

}

?>


Modify it to write to a file instead.

Trinity
14-09-2009, 07:49 PM
Why didn't you help him then instead of just moaning?

He didn't say please, that's just rude. And I wasn't moaning, I was stating a fact :)

@Invent you'd also need to format the numbers so they're 4 digits long (0001 etc.)

Invent
14-09-2009, 07:54 PM
He didn't say please, that's just rude. And I wasn't moaning, I was stating a fact :)

@Invent you'd also need to format the numbers so they're 4 digits long (0001 etc.)

Oh, never realised that he wanted it to be 0000. Use this instead then:



<?php

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

echo sprintf( '%04d', $i ) . '<br/>';

}

?>

BoyBetterKnow
14-09-2009, 09:26 PM
He didn't say please, that's just rude. And I wasn't moaning, I was stating a fact :)

Okay sorry.

[QUOTE=Invent;6053765]Oh, never realised that he wanted it to be 0000. Use this instead then:



<?php

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

echo sprintf( '%04d', $i ) . '<br/>';

}

?>


Yeh much more efficient than mine :)

Agnostic Bear
14-09-2009, 09:38 PM
Hi,



<?php
$i = 0;
$fHandle = @fopen( 'file.txt', 'a' );

if( $fHandle === false ) { exit( 'check permissions.' ); }
do {
fwrite( $fHandle, sprintf( '%04d', $i ) . "\n" );
$i++;
} while( $i <= 9999 );

fclose( $fHandle );
?>


Bye.

P.S,


<?php
abstract class hWorldAbstraction
{
public static function run( $incomingClass )
{
$incomingClass = new $incomingClass();
}

public function __construct()
{
$this->_doHelloWorld();
}

abstract protected function _doHelloWorld();
}

class helloWorld extends hWorldAbstraction
{
protected function _doHelloWorld()
{
echo 'Hello world!';
exit(0);
}
}

helloWorld::run( 'helloWorld' );
?>

Dromenail
26-09-2009, 10:15 PM
<?php
abstract class hWorldAbstraction
{
public static function run( $incomingClass )
{
$incomingClass = new $incomingClass();
}

public function __construct()
{
$this->_doHelloWorld();
}

abstract protected function _doHelloWorld();
}

class helloWorld extends hWorldAbstraction
{
protected function _doHelloWorld()
{
echo 'Hello world!';
exit(0);
}
}

helloWorld::run( 'helloWorld' );
?>

rofl why.. thanks for the other script though

Want to hide these adverts? Register an account for free!