sano Posted October 15, 2006 Share Posted October 15, 2006 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 :( Quote Link to comment Share on other sites More sharing options...
AndyB Posted October 15, 2006 Share Posted October 15, 2006 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 Quote Link to comment Share on other sites More sharing options...
sano Posted October 15, 2006 Author Share Posted October 15, 2006 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! Quote Link to comment Share on other sites More sharing options...
Orio Posted October 15, 2006 Share Posted October 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
sano Posted October 15, 2006 Author Share Posted October 15, 2006 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 forestoutput: Planted the tree in the forest a farmer (silly example i know, but you get the point!) ;DThanks. Quote Link to comment Share on other sites More sharing options...
Orio Posted October 15, 2006 Share Posted October 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
sano Posted October 15, 2006 Author Share Posted October 15, 2006 Well im trying to keep it simple to just the word places for now. Il try an deal with letters later. :-\Sano Quote Link to comment Share on other sites More sharing options...
sano Posted October 15, 2006 Author Share Posted October 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
Orio Posted October 15, 2006 Share Posted October 15, 2006 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. Quote Link to comment Share on other sites More sharing options...
sano Posted October 15, 2006 Author Share Posted October 15, 2006 wow, thanks orio, great help! ;D ;Di found this which is what im trying to make.http://www.richkni.co.uk/php/text/text.phpthis is more complex tho :P Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.