Jump to content

Cut-up engine


sano

Recommended Posts

Thanks, im looking at this now.

Im trying to create an engine that jumbles up words to create a new phrase. (or even new words!) So you type a phrase an it jumbles it into a new phrase!

so it could involve a random function ??? im not too sure tho. Thanks anyway!

Link to comment
Share on other sites

You mean a program that creates anagrams.
Do they have to be meaningful (a word) or just a random mix up?

If you are looking only for a random mix up, you can just use the function [url=http://www.php.net/manual/en/function.str-shuffle.php]str_shuffle()[/url].
But if you want to make in words out of the inputed word, it's a bit more complicated but I got an idea how to do.

Orio.
Link to comment
Share on other sites

I mean creating a new phrase from an input phrase.

Its for creating obscure lyrics and litrature. 


for example,

input: The farmer planted a tree in the forest

output: Planted the tree in the forest a farmer  (silly example i know, but you get the point!)  ;D

Thanks.
Link to comment
Share on other sites

First, you recieve the variable from a form (let's say the method you used is post, and the field's name was "words"):
$string=$_POST['words'];

Then you split it into an array using [url=http://www.php.net/manual/en/function.explode.php]explode()[/url] (by spaces):
$words=explode(" ", $string);

Then you use [url=http://www.php.net/manual/en/function.shuffle.php]shuffle()[/url] to randomize the order:
shuffle($words);

Then you use [url=http://www.php.net/manual/en/function.implode.php]implode()[/url] to join back the elements, using the glue as space:
$result=implode(" ",$words);

Finally, print the result:
echo $result;



Whole code looks like this:
[code]<?php

$string=$_POST['words'];

$words=explode(" ", $string);
shuffle($words);
$result=implode(" ",$words);

echo $result;

?>[/code]


Hope it helps :)


Orio.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.