random letters order in word (quick help)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

random letters order in word (quick help)

Post by spamyboy »

Can't find way to make random letters order in word, for e.g. if string is apple so it should look like ~ "pleap".
visitor-Q
Forum Commoner
Posts: 72
Joined: Mon Feb 05, 2007 1:40 am

Re: random letters order in word (quick help)

Post by visitor-Q »

spamyboy wrote:Can't find way to make random letters order in word, for e.g. if string is apple so it should look like ~ "pleap".
did you try

Code: Select all

shuffle($string)
Last edited by visitor-Q on Tue Feb 27, 2007 1:52 pm, edited 1 time in total.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

explode(), shuffle(), implode() ?
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

thanks !
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
visitor-Q
Forum Commoner
Posts: 72
Joined: Mon Feb 05, 2007 1:40 am

Post by visitor-Q »

wow that was a lot of posts in just a few seconds. quite a development of responses =)
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

you did ask for (quick help)... the default argument is (slow help)
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

here is what I made:

Code: Select all

http://php-only.com/
,kinde of fun text encoding.
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

If anyone whould help make it ajax, that would be wounderful.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

spamyboy wrote:here is what I made:

Code: Select all

http://php-only.com/
,kinde of fun text encoding.
spamyboy wrote: f anyone whould help make it ajax, that would be wounderful.

Um...what does that have to do with randomizing a word? If you need help on another topic, please make a new thread.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

nice looking form. bookmarked. :)
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

pickle wrote:
spamyboy wrote:here is what I made:

Code: Select all

http://php-only.com/
,kinde of fun text encoding.
spamyboy wrote: f anyone whould help make it ajax, that would be wounderful.

Um...what does that have to do with randomizing a word? If you need help on another topic, please make a new thread.
Image
here is exaple of forum output. midle letters are randomized, lol, havent you noticed that :) ?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I must admit, I didn't follow your link. I thought the phrase "http://php-only.com" was what you had made, not the webpage hosted there.

A pretty big brain fart on my part :oops: - sorry about that.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

it works best when the ascenders and descenders are in the correct places as well

NSG: Those are some niceforms ;-)
User avatar
spamyboy
Forum Contributor
Posts: 266
Joined: Sun Nov 06, 2005 11:29 am
Location: Lithuania, vilnius

Post by spamyboy »

Kieran Huggins wrote:it works best when the ascenders and descenders are in the correct places as well
How can that be made ?

Code: Select all

<?php
if($_POST['text']) {
$text=$_POST['text'];
$text = explode(" ", $text);
foreach( $text as $word )
{
$word_long=strlen($word)-2;
$first_letter=substr($word, 0, 1);
$random_letters=substr($word, 1, $word_long);
$random_letters=str_shuffle($random_letters);
$last_letter=substr($word, -1, 1);
$word=$first_letter.$random_letters.$last_letter;
$new_words[] = $word;
}
$text = implode(" ", $new_words);
echo $text;
}
?>
Post Reply