Skip to content

Instantly share code, notes, and snippets.

@titomus
Created August 10, 2017 07:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save titomus/36b87f77deeb93af94b038547bb88773 to your computer and use it in GitHub Desktop.
Save titomus/36b87f77deeb93af94b038547bb88773 to your computer and use it in GitHub Desktop.
Fonction PHP pour spinner du contenu SEO
<?php
function spin($txt){
$pattern = '#\{([^{}]*)\}#msi';
$test = preg_match_all($pattern, $txt, $out);
if(!$test)
return $txt;
$a_trouver = array();
$a_remplacer = array();
foreach($out[0] as $id => $match)
{
$choisir = explode("|", $out[1][$id]);
$a_trouver[] = $match;
$a_remplacer[] = $choisir[rand(0, count($choisir)-1)];
}
$reponse = str_replace($a_trouver, $a_remplacer, $txt);
return spin($reponse);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment