3
Contributors
15
Replies
16
Views
7 Years
Discussion Span
Last Post by Rewired
0

Use logic and imagination. To create a name, you must analyze what the letters, often found in names. Also, bundles of vowels and consonants.

0

Use logic and imagination. To create a name, you must analyze what the letters, often found in names. Also, bundles of vowels and consonants.

Oh forgot to say. I am new to this too

0

-> You can read your text file and from text file's content you can take first three or four words and use it as file name.

-> or use php random function to create random name.

function getRandomAlphaNumeric($intpLength = 16)
{
	$arrAlphaNumeric = array();
	$arrAlpha = range('A','Z');
	$arrNumeric = range(0,9);
	
	$arrAlphaNumeric = array_merge($arrAlphaNumeric, $arrAlpha, $arrNumeric);
	
	mt_srand((double)microtime() * 1234567);
	shuffle($arrAlphaNumeric);

	$strAlphaNumeric = '';
	for($x=0; $x<$intpLength; $x++)	
		$strAlphaNumeric .= $arrAlphaNumeric[mt_rand(0, (sizeof($arrAlphaNumeric)-1))];
	return $strAlphaNumeric;	
}
0
$strAlphaNumeric = '';

So is there would I put the source?

0

No changes in function.
you can use this function as:
$filename = getRandomAlphaNumeric(10);
So that you can have one random number in $filename.

what exactly ur scenario is??
Do you have txt files already on server or you want to upload txt file and rename it??

0

I have the txt file on my server and I do want to rename it when needed.

0
<?php
$sourcepath = "C:/my/path/";
$oldfilename = "myfile.txt";
$newfilename = getRandomAlphaNumeric(10);
rename($sourcepath.$oldfilename, $sourcepath.$newfilename );
echo "file ".$oldfilename." is now renamed to ".$newfilename;
?>

Hope this will help.

0
<?php
$sourcepath = "http://www.example.com/myfile.txt";
$oldfilename = "myfile.txt";
$newfilename = getRandomAlphaNumeric(10);
rename($sourcepath.$oldfilename, $sourcepath.$newfilename );
echo "file ".$oldfilename." is now renamed to ".$newfilename;
?>
<?php
$filename = getRandomAlphaNumeric(10);($intpLength = 16)

[B]	$arrAlphaNumeric = array();[/B]
	$arrAlpha = range('A','Z');
	$arrNumeric = range(0,9);
	
	$arrAlphaNumeric = array_merge($arrAlphaNumeric, $arrAlpha, $arrNumeric);
	
	mt_srand((double)microtime() * 1234567);
	shuffle($arrAlphaNumeric);

	$strAlphaNumeric = '';
	for($x=0; $x<$intpLength; $x++)	
		$strAlphaNumeric .= $arrAlphaNumeric[mt_rand(0, (sizeof($arrAlphaNumeric)-1))];
	return $strAlphaNumeric;	
}
?>

Ok I added the code as you see and I get this error on line 11 (one bolded above:
Parse error: syntax error, unexpected T_VARIABLE

Edited by Rewired: n/a

0

I think you don't know how to use function.

<?php

function getRandomAlphaNumeric($intpLength = 16)
{
	$arrAlphaNumeric = array();
	$arrAlpha = range('A','Z');
	$arrNumeric = range(0,9);
	
	$arrAlphaNumeric = array_merge($arrAlphaNumeric, $arrAlpha, $arrNumeric);
	
	mt_srand((double)microtime() * 1234567);
	shuffle($arrAlphaNumeric);

	$strAlphaNumeric = '';
	for($x=0; $x<$intpLength; $x++)	
		$strAlphaNumeric .= $arrAlphaNumeric[mt_rand(0, (sizeof($arrAlphaNumeric)-1))];
	return $strAlphaNumeric;	
}

$sourcepath = "C:/my/path/"; // this must be local pc path not LIVE URL
$oldfilename = "myfile.txt";
$newfilename = getRandomAlphaNumeric(10);
rename($sourcepath.$oldfilename, $sourcepath.$newfilename );
echo "file ".$oldfilename." is now renamed to ".$newfilename;
?>
0

Find this link, you can see php function example here.

And you want to rename your file which is already there on your server .. right?
So use path not url.

0

ITs renaming the file? Is it suppose to, because I wanted it to generate a name from the text file.

0

php code for you:

<?php
		
	$content = file_get_contents("http://192.168.0.1/domain/test.txt");	
	$content = ereg_replace("[\n\r]", "##", $content);
	$ar = explode('####',$content);
	$rand_keys = array_rand($ar, 1);
	$random = $ar[$rand_keys];
	echo $random;
	
?>

test.txt :

Computer
World
Hello
Monday
File
Mouse
Tree

Take care that all words in test.txt must be in next line.

0

It's weird. It puts them all of them like this:

Computer##World##Hello##Monday##File##Mouse##Tree

Can I just get one of them at random?

0

it was working at my end.. try this.

<?php
		
	$content = file_get_contents("http://192.168.0.1/domain/test.txt");	
	$content = ereg_replace("[\n\r]", "##", $content);
	$ar = explode('##',$content);
	$rand_keys = array_rand($ar, 1);
	$random = $ar[$rand_keys];
	echo $random;
	
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.