<?php

if(!function_exists('file_get_contents'))
{
    
# Exists in PHP 4.3.0+
    
function file_get_contents($filename)
    {
        return 
implode(''file($filename));
    }
}

if(!
function_exists('file_put_contents'))
{
    
# Exists in PHP 5
    
function file_put_contents($filename$data)
    {
        
$fp fopen($filename'w');
        
$bytes fwrite($fp$data);
        
fclose($fp);
        return 
$bytes;
    }
}

$wikitext "";

function 
subPageTitle($matches)
{
    global 
$wikitext;

    
$wikitext .= "* [[$matches[1]]]\n";
    return 
$matches[0];
}

$text file_get_contents("alltalkpages.txt");

// preg_replace_callback("/title=\"(.*)\">/", 'subPageTitle', $text);

for($x 0$x <= strlen($text); $x++)
{
    
$titlepos strpos($text'title'$x);
    echo 
"Title Position: $titlepos\n";
    if(
$titlepos === false)
        break;
    
    
$endpos strpos($text'"'$titlepos 7);
    echo 
"End Position:   $endpos\n";
    
$title substr($text$titlepos 7$endpos - ($titlepos 7));
    echo 
"Title: $title\n";
    
$wikitext .= "([[:Talk:$title|talk]])\n";

    
$x $endpos;
}

file_put_contents("newtalkpages.txt"$wikitext);

?>