5ubliminal@twitter

textBlender - Generating Text Based on Given Patterns : 5ubliminal's TellinYa

<a href="http://www.tellinya.com/art2/268/">textBlender - Generating Text Based on Given Patterns : 5ubliminal's TellinYa</a>
5ubliminal's YAMS
This has been integrated in two free tools available for download! The Text Blender and the Article Blender.
The most basic and obvious tip …

… drove all sphinners crazy! SlightlyshadySEO gave out a tip on how to variate the anchor text (text in your links) when doing link exchange or link spamming. And he gave a basic function to achieve this.

It is time for my text blender to enjoy its well diserved popularity. This function is special becase it takes imbricated blocks of options and processes them all.

The PHP Script:
  1. <?
  2. //------------------------------------------------------
  3. //-- Copyright 5ubliminal 2007 - tellinya.com!
  4. function textBlender($str,$splitters="|"){
  5.     //-- While we find a choice entity ... we translate it and try again!
  6.     while(preg_match("/{([^{}]+)}/i",$str,$slices,PREG_OFFSET_CAPTURE)){
  7.         //-- Using preg_match we just find first occurence. This is to ensure that,
  8.         //-- if we use same pattern more then once, it will not always be replaced
  9.         //-- with same string!
  10.         $slices = $slices[1];
  11.         //-- The selection entity matched
  12.         $matchstr = $slices[0];
  13.         //-- The offset in the original string. We need it to insert it where it was!
  14.         //-- We don't use str_replace as we might replace more choice entities that
  15.         //-- look the same with the same thing hence ruining this function!
  16.         $matchpos = (int)$slices[1];
  17.         //-- We split the choice entity by ,; . You can change the splitters eas you
  18.         //-- wish.
  19.         $pieces = preg_split("/[".$splitters."]+/", $matchstr);
  20.         //-- Let's not use rand() if only one choice is found in entity!
  21.         if(count($pieces)>1){
  22.             $piececnt = count($pieces);
  23.             $randseeds = rand(1,10);
  24.             $randseede = $randseeds + rand(1,10);
  25.             $randpos = rand($randseeds * $piececnt, $randseede * $piececnt);
  26.             $pieces = $pieces[$randpos % $piececnt];
  27.         } else $pieces = $pieces[0];
  28.         //-- We take the original string before the match
  29.         $headerslice = substr($str, 0, $matchpos-1);
  30.         //-- We take the original string after the match
  31.         $footerslice = substr($str, $matchpos+strlen($matchstr)+1);
  32.         //-- We combine header, footer and chosen entity to a new string!
  33.         $str = $headerslice . $pieces . $footerslice;
  34.         //-- We try again on the new string ...
  35.     }
  36.     return $str;
  37. }
  38. //------------------------------------------------------
  39. ?>
Why is this function best of its kind?

I'm just being modest here :) It is because it can take text like: (I know the text look really stoopid but that's the point :))

{{{Fast|Expensive|Shiny|Red|Blue} shoes make|An {Expensive|Pretty|Hot} shoe makes} me {look|appear|seem} {rich|expensive} and {cool|pretty|hot|sexy|stoopid|tall}!|It's all {a lie|misleading informations|smoke and mirrors|a joke|a test}!}

and get something like this out of it:

  • It's all misleading informations!
  • Blue shoes make me seem rich and hot!
  • Red shoes make me appear rich and pretty!
  • Fast shoes make me look rich and stoopid!
  • Blue shoes make me look rich and sexy!
  • It's all a lie!
  • Shiny shoes make me seem expensive and cool!
  • It's all a joke!
  • Shiny shoes make me seem rich and hot!
  • An hot shoe makes me appear rich and stoopid!

As you may notice the rules are imbricated. So they are parsed recursivley and translated one at a time. I also allow you to set as parameter the separator but I always use | as it's not used too often except for coders. Look below how it all really looks like:

{
    {
        {Fast|Expensive|Shiny|Red|Blue} shoes make
        |
        An {expensive|pretty|hot} shoe makes
    }
    me
    {look|appear|seem} {rich|expensive} and {cool|pretty|hot|sexy|stoopid|tall}!
    |
    It's all {a lie|misleading informations|smoke and mirrors|a joke|a test}!
}

So many brenches of possibility are resolved with style. I used to have this function work with explode and a lot of string work to reach this but sience I got into regexp … things will never be the same again.

What can you use this for:

Randomize link exchange text after your own patterns aiming for a keyphrase but providing variations. Spamming … easier to produce different relevant text. Content generation: write 1 page output 10 and so on …

Enjoy!

PS: I got it in C++ if anyone cares :)

4 Comments Posted By Readers :

Add your comment
#1 m0nkeymafia from Great Britain
Posted on Tuesday, 15 January, 2008
I would quite like a copy of the C++ version, namely to check out how you wrote it. Did you go for std library string functions or something else? Gimmeh! lol
#2 5ubliminal web
Posted on Tuesday, 15 January, 2008
I have never used the std! I coded myself, during 9 years, my own (header only 250k+ lines) library much more useful than the std!
So I can write a lot with few lines backed up by many others put together in pretty classes.

I use GRETA regexp in C++ (I hate std like BOOST) and works miracles.
#3 fl0rine2 from United States
Posted on Tuesday, 05 February, 2008
Thank you for this
#4 5ubliminal web
Posted on Tuesday, 05 February, 2008
Your welcome :) Checkout the two new links I added on top of the post.
5ubliminal's TellinYa.com SEM & SEO Blog © 2007 - All rights reserved unless mentioned otherwise .
Rendered On : [Monday, 08 February, 2010 - 22:18:31 GMT]   No Ajax / Flash Used Here
" textBlender - Generating Text Based on Given Patterns : 5ubliminal's TellinYa "
Close
Tellinya.com is relocating to blog.5ubliminal.com. This blog is no longer maintained and comments are no longer accepted / answered.