itchy

A little something for ya, nothing too fancy but i find it very useful, it seems to weave its way into all my sites/spam scripts somewhere along the way.
this function outputs a random syn block of text for use in metatags, content (works well above a block of

markov

  on mfa sites), dynamic rss feeds well anywhere you need some readable non dupe content a la content maestro et al:

function synomizer($text) {
    $textarray = explode(" ",$text);
        foreach ($textarray as $t){
            if (ereg("^[a-zA-Z0-9]",$t)){$string .= $t." ";}
            if (ereg("^{",$t)) {
            $syn = preg_replace("/{/","",$t);
            $syn = preg_replace("/}/","",$syn);
            $syn = preg_replace("/_/"," ",$syn);
            $syn = explode("|",$syn);
            $string .= $syn[mt_rand(0,count($syn)-1)]." ";
            }
        } 
    return $string;
}   


usage is simple as per:

$text = "{need|require} some {lead_in_your_pencil|extra_girth|floppy_lolly_enhancement}?" . 
        " {buy_my_crap|visit_my_site}, etc, etc.."; 
$result = synomizer($text);
print $result;


the only thing to remember is to add underscores between multiple words in the blocks "{variant_a|variant_b}". i couldn't think of a better way to do this at the time. They are <>not needed for multiple words outside the blocks. Comments and enhancements welcome.
enjoy
itchy 

m0nkeymafia

I unfortunately have NO idea what this does?
Anyone care to elaborate feel free to let me know.

Im a nice boy - not been tainted by this kind of stuff yet...taint me Applause

thedarkness

run1: require some lead in your pencil visit my site, etc, etc..
run2: need some lead in your pencil buy my crap etc, etc..
run3: require some floppy lolly enhancement? visit my site, etc, etc..
run4: require some extra girth buy my crap etc, etc..

You get the idea.

Cheers,
td

m0nkeymafia

Ah right cool

So say you could basically create some random crap content, hopefully different enough to make SEs think its good enough to rank for. And you get a load of your keywords in there. I assume, to target long tail sorta keywords?

So you may have a database full of keywords you want to rank for, and maybe alternatives n stuff, you can have some standard text, then have a page for each one!?

Automagically generated using the synomizer n stuff?

thedarkness

<>No, we would never do something like that...... yeah.... that's it....  Applause

Cheers,
td

perkiset

Applause  Applause

KaptainKrayola

the Kaptain sees this forum going downhill fast.  what's next, gayjacking threads?

perkiset

Crass MoFo.

Just for that, you're getting stuck with you're own smiley you bastard.

Applause

Don't say I never gave ya nuthin...  Applause

dink

ROFL

m0nkeymafia

wtf?

KaptainKrayola

Applause

Perk is our hero! YAR!

SEO

 idiot

no your just gay for him.... (sorry felt obliged)

perkiset

You're just jealous, biatch.

thedarkness

monkey: Don't let these loons scare you off..... you get used to them eventually..... unfortunately  Applause

SI: Stop trying to gay up this thread  Applause

Cheers,
td

m0nkeymafia

lol ta dude
id offer up a man hug but dont wanna encourage more gayness  Applause

guitarpaul

lol Applause
nice script, ty

Makiavel

Hello!
This is a faster version of the above script.  Also it doesn't need underscores anymore.

function synomizer($text) {
$txt = preg_split("/{|}/", $text);
foreach($txt as $key => $t){
if($key%2){
$syn = preg_split("/|/", $t);
$txt[$key] = $syn[mt_rand(0,count($syn)-1)];
}
}
$string = implode("", $txt);
return $string;



And how to use it:
$text = "{need|require} some {lead in your pencil|extra girth|floppy lolly enhancement}?" . 
        " {buy my crap|visit my site}, etc, etc.."; 
$result = synomizer($text);
print $result;

perkiset

I love this thread. The syntax for the syn options is good and this actually plays nicely into <>my plan for world domination a couple little apps I am writing.

Hehe.  Applause

/p

jsp123

Here is the version I made:

Note if you uncomment one second comment you get a list of the variables you need to fill in for the replaces

Usage:
$text = "I love (mango|fruit|tropical fruit|all [kinds of food|fruit]|{fruit-name})";

$arr = array('fruit-name'=>'Mangos Again') <-- should probably tweak it to allow arrays here


<

php

 
function varplace($arr, $str) {

if(array_key_exists($str,$arr)){
//echo $str."<br />";
return $arr[$str];


} else {
//echo $str."<br /> ";
return "$str";
}
}

function con($text, $arr){
global $db;
preg_match_all("#[([^[]]*?)]#", $text, $replaces);

$c = count($replaces[0]);
if($c > 1){
$i = 0;
foreach($replaces[1] as $o){

$replace = $replaces[0][$i++];
$options = explode("|",$o);
$oc = count($options);

if($oc > 0){
srand(microtime()*100000000);
$r = rand(0,$oc-1);
$with = $options[$r];
$text = str_replace($replace, "".$with."", $text);
}

}
}

preg_match_all("#(([^()]*?))#", $text, $replaces);

$c = count($replaces[0]);
if($c > 1){
$i = 0;
foreach($replaces[1] as $o){

$replace = $replaces[0][$i++];
$options = explode("|",$o);
$oc = count($options);

if($oc > 0){
srand(microtime()*100000000);
$r = rand(0,$oc-1);
$with = $options[$r];
$text = str_replace($replace, "".$with."", $text);
}

}
}


$text = preg_replace('/{(.*?)}/e', 'varplace($arr, '$1')', $text);


return $text;
}
?>


I know it is bloated, and could be done with 3 lines or something, only runs once and then caches the results in my script so whatever.

perkiset

I wanted to weigh in using a couple little

PHP

  tricks to make this very efficient.

Here is code that takes advantage of the <<< operator in

PHP

  as well as the fact that object functions, as opposed to real functions, can be used to call for values in the middle of the input text. Note that in the real world there would be other functions in the class to take advantage of text file or array input rather that the very manual method listed here.


<?

php

 

class simpleSyn
{
protected $repArr = array();
function addSyn($token, $repVal) { $this->repArr[$token][] = $repVal; }
function getSyn($token) { return $this->repArr[$token][rand(0, count($this->repArr[$token]) - 1)]; }
}

$syn = new simpleSyn();
$syn->addSyn('when', 'Now is the');
$syn->addSyn('when', 'Sometime will be the');
$syn->addSyn('when', 'There will never be a');

$syn->addSyn('kind', 'good');
$syn->addSyn('kind', 'polite');
$syn->addSyn('kind', 'shifty');
$syn->addSyn('kind', 'taky-like');

$syn->addSyn('person', 'men');
$syn->addSyn('person', 'women');
$syn->addSyn('person', 'children');
$syn->addSyn('person', 'dog-lovers');

$syn->addSyn('whatever', 'country');
$syn->addSyn('whatever', 'forum');
$syn->addSyn('whatever', 'family');
$syn->addSyn('whatever', 'political party');


for ($i=0; $i<10; $i++)
{
echo <<<TEXT
{$syn->getSyn('when')} time for all {$syn->getSyn('kind')} {$syn->getSyn('person')}
to come to the aid of their {$syn->getSyn('whatever')}.
TEXT;
}

?>


Some output:

Now is the time for all good children to come to the aid of their family.
There will never be a time for all polite children to come to the aid of their country.
Sometime will be the time for all taky-like women to come to the aid of their forum.
There will never be a time for all good children to come to the aid of their political party.
There will never be a time for all good women to come to the aid of their family.
Now is the time for all good children to come to the aid of their forum.
There will never be a time for all polite children to come to the aid of their country.
Sometime will be the time for all good dog-lovers to come to the aid of their political party.
Now is the time for all shifty children to come to the aid of their country.
Now is the time for all good women to come to the aid of their family.
[/pre] Applause,
/p

jsp123

thanks perk will try your style of my next one.

m0nkeymafia

Whoa whoa whoa perky
<<< ... tell more!

p.s. nice class, simplicity rocks

perkiset

About the <<< ?

Really simple - I don't know the name, but it's kind of a "Here comes a text block" operator. There is something similar in

PERL

 , which I believe is where it comes from. You can echo, print or assign with it, and it goes like this:

$aVar = <<<AWORD
text
text
text
text
AWORD;

Immediately after the <<< you must have some word - and when you use that EXACT word again at the root of a line followed by a semi colon, the interpreter knows you're done. Variable dereferences work just fine in it, which is what I took advantage of in the class above. This is kind of opposite of inline

PHP

  in an HTML page... it's inline text blocks in a

PHP

  page.

I love it, use it pretty often. Good luck!
/p

m0nkeymafia

Amazing, I've started using echo 'blah',$blah,'foo'; loads now too
Perk is slowly improving the quality of

PHP

  throughout the world Applause

I'm guessing its a C++ stream operator throwback ?

thedarkness

heredoc syntax, see this page http://www.

php

 

.net

 /manual/en/language.types.string.

php

  and http://en.wikipedia.org/wiki/Here_document

My personal belief is that it actually started in one of the early *nix shells as i remember using it long ago in HP-UX8, but I could be wrong.

Cheers,
td

perkiset

It was in

PERL

  I think in some form way before

PHP

  too...


Perkiset's Place Home   Politics @ Perkiset's