Jump to content

Archived

This topic is now archived and is closed to further replies.

sano

Cut-up engine

Recommended Posts

Hi,

Im trying to create a cut-up engine, re-arranging a text input to spit out a different text on the output.


I need a basic idea on what i need todo. Can anyone help me? I have basic php knowledge but im stumped  :(

Share this post


Link to post
Share on other sites
I have no idea what it is you're hoping to do, but the substr() function might be part of the solution.

http://ca.php.net/manual/en/function.substr.php

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
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.

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
Do you want only to change the word's places, or change the letters themselves too (like in [url=http://www.ssynth.co.uk/~gay/anagram.html]this site[/url]).

Orio.

Share this post


Link to post
Share on other sites
Well im trying to keep it simple to just the word places for now.

Il try an deal with letters later.  :-\


Sano

Share this post


Link to post
Share on other sites
Can anyone give me some advice on where to start with this?  (what i need to use?)

I want to create a word scrambler that changes the words in a sentance around randomly.


thanks in advance.


Share this post


Link to post
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.

Share this post


Link to post
Share on other sites
wow, thanks orio, great help!  ;D ;D


i found this which is what im trying to make.

http://www.richkni.co.uk/php/text/text.php

this is more complex tho  :P

Share this post


Link to post
Share on other sites

×

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.