<?
$str = file_get_contents('text.ori');
$badChars = array(chr(10), chr(13));
$str = str_replace($badChars, ' ', $str);
$newstr = '';
while($newstr != $str)
{
if($newstr != '')$str = $newstr;
$newstr = str_replace(' ', ' ', $str);
}
$words = explode(' ', $str);
$links = file('links.txt');
$cWords = count($words);
$cLinks = count($links);
if($cWords>$cLinks)
{
$step = intval($cWords/$cLinks);
for($i = 0; $i < $cLinks; $i++)
$words[$i*$step] = '<a href="'.str_replace($badChars, '', $links[$i]).'">'.$words[$i*$step].'</a>';
file_put_contents('text.res', implode(' ', $words));
}
?>