Rutin aşağıda hipermetnin bir giriş akışı üzerinde iki taramaları yapar. İlk geçiş kullanıcı tanımlı ifade seçenekleri bir spin yerine geçer. İkinci pass altında bir doReplace fonksiyonunda etiketleri toplama yerini bulmak.
Ben sadece optimize olabilir nasıl önerileri arıyorum. Olduğu gibi herhangi bir performans sorunları yaşıyorum. Ama ölçeklenebilirlik için kurmak istiyorum.
/* FIND REPLACE SPIN
--------------------------------------------------------------------*/
function doReplace($content)
{
// content is a precompiled text document formatted with html and
// special using replacement tags matching the $tags array collection below
$tags = array('[blog-name]', '[blog-url]', '[blog-email]');
$replacements = array('value1', 'value2', 'value3');
$content = str_replace($tags, $replacements, $content);
return $content;
}
function doSpin($content) {
// the content also has phrase option tags denoted by [%phrase1|phrase2_|phrase3%]
// delimiters throughout the text.
return preg_replace_callback('!\[%(.*?)%\]!', 'pick_one', $content);
}
function pick_one($matches) {
$choices = explode('|', $matches[1]);
return $choices[rand(0, count($choices)-1)];
}
$my_source_page = file_get_contents('path/to/source';}
$my_source1_spin = doSpin($my_source_page);
$my_source1_replace = doReplace($my_source1_spin);
$my_source1_final = addslashes($my_source1_replace);
//Now do something with $my_source1_final