PHP Spintax - Made Easy

If you're adding multiple pages for GEO purposes with similar content, why not make each page more unique by varying the text/content per page. I have designed a php class (GEOspintax) that will do just that. It's very easy to use. I have added a safe Fixed rotating rule so that each page that uses the spintax code will only ever use one version of the text when reloaded. This ensures that each page in the eyes of Google is slightly different.

<?
/**
* GEOspintax - A helper class to process spintax strings.
* Copyright: https://lj.digital - 2021
* @name GEOspintax
* @author Lee Johnson
*/
class GEOspintax
{protected $useFixedSeed = false;
public function __construct( $bFixed = false, $cSeed = null )
{if ($bFixed){$this->useFixedSeed = $bFixed;
if (null == $cSeed){$cSeed = $_SERVER['REQUEST_URI'];}mt_srand( crc32( $cSeed ) );}return $this;}
public function process($text){return preg_replace_callback('/\{(((?>[^\{\}]+)|(?R))*?)\}/x',array($this, 'replace'),$text);}
public function replace($text){$text = $this->process($text[1]);$parts = explode('|', $text);
// We want the same version returned each time
if ($this->useFixedSeed){
// Need to use alternate method of selecting random element
return $parts[ mt_rand(0, count($parts) - 1) ];}return $parts[ array_rand($parts) ];}}
?>

<? /* Example Usage */ $GEOspintax = new GEOspintax(); $string = '{}'; echo $GEOspintax->process($string); ?>
<? /* Nested Spinning Example */ $GEOspintax = new GEOspintax(); echo $GEOspintax->process('{{}}'); ?>

Add your'e different semantic synonyms that you would like to use between {} - e.g. {Hello|Howdy|Hola}. (This code can be used as many times as you like on any given page). The class has been written to randomise and fix the php for each of on-page snippet you add.

<? /* Example of using FIXED method */ $GEOspintaxFixed = new GEOspintax( true );
/* Using default seed */ $string = '{}';
/* Will always be the same value */ echo $GEOspintaxFixed->process($string); ?>

This is more than a wise thing to use. If you just replicate the same page apart from the GEO area that you are looking to target then the pages will be classed as too similar. This class will help each page you produce be more unique.

<? /* Fixed but initial random seed */
$GEOspintax = new GEOspintax(); $string = '{}'; echo $GEOspintaxFixed->process($string); ?>