Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help for simple case

Status
Not open for further replies.

paispatin

Technical User
Oct 21, 2003
62
A1
Dear all,

I have 3 simple cases, and waiting for help:

1. case :
$a="abcdefg" (string)
How to get it as "efg" and "abc" and "cde"? (string result)

2. case :
$b=1234567 (numeric)
How to get it as 567 and 345 ? (still numeric result)

3. case :
How to generate a random number/string?

Thank you in advance.

 
1. Look into the Substr() function.

2. Again, look into the Substr() function.

3. Random number: look into the rand() or mt_rand() functions.

Random string: You'd most likely set up a for loop and use the chr() function. Below is an example.

Code:
// build a 5-character random string
$random_string = '';
for ($i = 0; $i < 5; $i++) {
    // generate number between 97 and 122, which are the 
    // ascii values of letters a-z (lowercase)
    $num = rand(97, 122);
    $random_string .= chr($num);
}
echo $random_string;

*cLFlaVA
----------------------------
A pirate walks into a bar with a huge ship's steering wheel down his pants.
The bartender asks, "Are you aware that you have a steering wheel down your pants?"
The pirate replies, "Arrrrr! It's driving me nuts!
 
Yes clflava, that's what I need. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top