Created
August 10, 2017 07:04
-
-
Save titomus/36b87f77deeb93af94b038547bb88773 to your computer and use it in GitHub Desktop.
Fonction PHP pour spinner du contenu SEO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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