Welcome to the GoFuckYourself.com - Adult Webmaster Forum forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Post New Thread Reply

Register GFY Rules Calendar
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >
Discuss what's fucking going on, and which programs are best and worst. One-time "program" announcements from "established" webmasters are allowed.

 
Thread Tools
Old 05-11-2012, 05:59 PM   #1
Dcat
Confirmed User
 
Dcat's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Mexico
Posts: 1,607
PHP code to rearrange sentances??

Anyone know of a php function, or snippet of code I can use to rearrange/randomize the order of sentences in a block of text?
Dcat is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 06:21 PM   #2
HomerSimpson
Too lazy to set a custom title
 
HomerSimpson's Avatar
 
Industry Role:
Join Date: Sep 2005
Location: Springfield
Posts: 13,826
shuffle()

__________________
Make a bank with Chaturbate - the best selling webcam program
Ads that can't be block with AdBlockers !!! /// Best paying popup program (Bitcoin payouts) !!!

PHP, MySql, Smarty, CodeIgniter, Laravel, WordPress, NATS... fixing stuff, server migrations & optimizations... My ICQ: 27429884 | Email:
HomerSimpson is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 06:22 PM   #3
EddyTheDog
Just Doing My Own Thing
 
EddyTheDog's Avatar
 
Industry Role:
Join Date: Jan 2011
Location: London, Spain, New Zealand, GFY - Not Croydon...
Posts: 25,041
You could do it with any spinner type setup....
__________________
-

Chaturbate Script - https://gfy.com/fucking-around-and-b...er-issues.html - Now supports White Labels
EddyTheDog is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 06:23 PM   #4
AdultKing
Raise Your Weapon
 
AdultKing's Avatar
 
Industry Role:
Join Date: Jun 2003
Location: Outback Australia
Posts: 15,601
If you want to shuffle the same every time then use this function

Code:
<?php
/* $seed variable is optional */
function SEOshuffle(&$items, $seed=false) {
  $original = md5(serialize($items));
  mt_srand(crc32(($seed) ? $seed : $items[0]));
  for ($i = count($items) - 1; $i > 0; $i--){
    $j = @mt_rand(0, $i);
    list($items[$i], $items[$j]) = array($items[$j], $items[$i]);
  }
  if ($original == md5(serialize($items))) {
    list($items[count($items) - 1], $items[0]) = array($items[0], $items[count($items) - 1]);
  }
}
?>
*Taken from php.net
AdultKing is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 08:23 PM   #5
Dcat
Confirmed User
 
Dcat's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Mexico
Posts: 1,607
Here's what I'm looking for..

Example:

$string = "Lorem ipsum is the most common form of "Greeking". However more and more people are sick and tired of using the same sample text over and over again. Also lorem ipsum is in latin and it may not always be the best choice. We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here. ";

$newstring = awesomeSentenceShufflingFunction($string);

echo $newstring;

-----

Output:

We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here. However more and more people are sick and tired of using the same sample text over and over again. Also lorem ipsum is in latin and it may not always be the best choice. Lorem ipsum is the most common form of "Greeking".

Last edited by Dcat; 05-11-2012 at 08:34 PM..
Dcat is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 08:35 PM   #6
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
$sentences = explode('.', $string);
shuffle($sentences);
echo implode(' ', $sentences);
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 08:44 PM   #7
Dcat
Confirmed User
 
Dcat's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Mexico
Posts: 1,607
Quote:
Originally Posted by Brujah View Post
$sentences = explode('.', $string);
shuffle($sentences);
echo implode(' ', $sentences);
Something like that, but that would also consider all the potential variations such as ! !! !!! ? ." word.word(<-no space) ..etc
Dcat is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 08:56 PM   #8
garce
Confirmed User
 
garce's Avatar
 
Industry Role:
Join Date: Oct 2001
Location: Toronto
Posts: 7,103
Sentances? Try Google translate.
garce is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 09:19 PM   #9
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
$sentences = preg_split( '/\.|\!+/', $s);
array_map( 'trim', $sentences);
echo implode( '. ', $sentences );
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 09:28 PM   #10
shake
frc
 
Industry Role:
Join Date: Jul 2003
Location: Bitcoin wallet
Posts: 4,663
Basically you'll want to load them into an array and mix them up. Naturally they won't make a lot of sense afterwords.
shake is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 10:09 PM   #11
glowlite
Confirmed User
 
Industry Role:
Join Date: Dec 2005
Location: Arizona/Indiana
Posts: 366
Sorry, if you can't spell than PHP is above your pay grade.
glowlite is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 10:24 PM   #12
Dcat
Confirmed User
 
Dcat's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Mexico
Posts: 1,607
Quote:
Originally Posted by Brujah View Post
$sentences = preg_split( '/\.|\!+/', $s);
array_map( 'trim', $sentences);
echo implode( '. ', $sentences );
Thanks.

I might have to go ahead and roll my own using something similar.
Dcat is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 10:37 PM   #13
Dcat
Confirmed User
 
Dcat's Avatar
 
Industry Role:
Join Date: Aug 2003
Location: Mexico
Posts: 1,607
Quote:
Originally Posted by glowlite View Post
Sorry, if you can't spell than PHP is above your pay grade.
Yeah, ok smart ass. "sentences" ....I'm DOG fucking tired today.

Did you read what I wrote in the same post?

"Anyone know of a php function, or snippet of code I can use to rearrange/randomize the order of sentences in a block of text?"

..seems "sentences" was spelled correctly.

Did you notice my example.. $newstring = awesomeSentenceShufflingFunction($string);

...Sentences is spelled correctly there too.

..give me a fucking break.

Anyways, I need sleep. I'm out.

Thanks to all of those with something constructive to offer. I'll check back tomorrow.
Dcat is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 10:59 PM   #14
sleazydoesit
Confirmed User
 
sleazydoesit's Avatar
 
Industry Role:
Join Date: May 2011
Location: Seoul, Korea
Posts: 343
Quote:
Originally Posted by glowlite View Post
Sorry, if you can't spell than PHP is above your pay grade.
Don't be throwing stones if you can't use "then" and "than" correctly
sleazydoesit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-11-2012, 11:10 PM   #15
glowlite
Confirmed User
 
Industry Role:
Join Date: Dec 2005
Location: Arizona/Indiana
Posts: 366
Quote:
Originally Posted by sleazydoesit View Post
Don't be throwing stones if you can't use "then" and "than" correctly
idiot ...

http://www.wikihow.com/Use-Than-and-Then
glowlite is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-12-2012, 01:25 AM   #16
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,383
:2cents

Quote:
Originally Posted by Brujah View Post
$sentences = preg_split( '/\.|\!+/', $s);
array_map( 'trim', $sentences);
echo implode( '. ', $sentences );
The code above won't work because:
1) it doesn't actually shuffle sentences;
2) it doesn't split sentences that end with "..." and "?";
3) the result of array_map() will be lost;
4) all exclamation marks will be replaced with dots.

So here is the fixed version:

preg_match_all('/.*?[\?|\.\.\.|\.|\!]+/s', $s, $sentences);
$sentences[0] = array_map('trim', $sentences[0]);
shuffle($sentences[0]);
echo implode(' ', $sentences[0]);
__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-12-2012, 01:30 AM   #17
just a punk
So fuckin' bored
 
just a punk's Avatar
 
Industry Role:
Join Date: Jun 2003
Posts: 32,383
Or even shorter:

preg_match_all('/.*?[\?|\.\.\.|\.|\!]+/s', $s, $sentences);
shuffle($sentences[0]);
echo implode(' ', array_map('trim', $sentences[0]));

__________________
Obey the Cowgod
just a punk is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-12-2012, 01:44 AM   #18
sleazydoesit
Confirmed User
 
sleazydoesit's Avatar
 
Industry Role:
Join Date: May 2011
Location: Seoul, Korea
Posts: 343
Quote:
Originally Posted by glowlite View Post
I repeat, don't be throwing stones if you can't use "then" and "than" correctly, and if you rely on a fucking website called Wikihow for grammar lessons then you have some serious problems.
sleazydoesit is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-12-2012, 08:31 AM   #19
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
Quote:
Originally Posted by CyberSEO View Post
Or even shorter:

preg_match_all('/.*?[\?|\.\.\.|\.|\!]+/s', $s, $sentences);
shuffle($sentences[0]);
echo implode(' ', array_map('trim', $sentences[0]));

I was drunk coding! I'll take a look and give it a try.
__________________
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Old 05-12-2012, 09:31 AM   #20
Brujah
Beer Money Baron
 
Brujah's Avatar
 
Industry Role:
Join Date: Jan 2001
Location: brujah / gmail
Posts: 22,157
I like this version so far:

Code:
$string = <<<EOS
Lorem ipsum is the most common form of "Greeking". However more and more people are sick and tired of using the same sample text over and over again. Also lorem ipsum is in latin and it may not always be the best choice. We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here.
Adding a few extra examples... you mean like this? Hmm, what the hell?!!!
EOS;

preg_match_all( '/[^.?!]+[.?!]+/m', $string, $matches );
$sentences = array_map( 'trim', $matches[0] );
shuffle( $sentences );
$sentences = array_map( 'ucfirst', $sentences );
echo implode( ' ', $sentences );
This kept the mix of punctuation and any number of it together, and in case of a fragment with lowercase first letter it'll fix that.

Outputs:
However more and more people are sick and tired of using the same sample text over and over again. We tried to have text generated in some of the most widely used languages but if you are in desperate need of random text in your own language, send us an email and we'll add it here. You mean like this? Adding a few extra examples... Hmm, what the hell?!!! Lorem ipsum is the most common form of "Greeking". Also lorem ipsum is in latin and it may not always be the best choice.
__________________

Last edited by Brujah; 05-12-2012 at 09:45 AM.. Reason: fixing ucfirst
Brujah is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote
Post New Thread Reply
Go Back   GoFuckYourself.com - Adult Webmaster Forum > >

Bookmarks



Advertising inquiries - marketing at gfy dot com

Contact Admin - Advertise - GFY Rules - Top

©2000-, AI Media Network Inc



Powered by vBulletin
Copyright © 2000- Jelsoft Enterprises Limited.