and ) $pagesarray = preg_split('/<.+?>/', $pagelinks, null, PREG_SPLIT_OFFSET_CAPTURE|PREG_SPLIT_NO_EMPTY); //print_r($pagesarray); // Setting up blank array to store the new HTML page titles $pagenames = Array(); // Loop through page titles, adding a to the first word and also storing the length of the page title for ($i = 0; $i < (count($pagesarray) - 1); $i++) { $pagenames[$i][1] = $pagesarray[$i][1]; $pagenames[$i][2] = strlen($pagesarray[$i][0]); if (strpos($pagesarray[$i][0], ' ') === false) { $pagenames[$i][0] = ''.$pagesarray[$i][0].''; } else { $thistitle = explode(' ', $pagesarray[$i][0]); $thistitle[0] = ''.$thistitle[0].''; $pagenames[$i][0] = implode($space, $thistitle); } } // $pagenames[x][0] = HTML-formatted page title // $pagenames[x][1] = character offset (strpos) in $pagelinks // $pagenames[x][2] = length of page title // Setting up empty string for new HTML page menu $newlinks = ''; // Replace vanilla page titles in $pagelinks with HTML-formatted titles for ($i = 0; $i < count($pagenames); $i++) { if ($i == 0) { // On the first loop, adds everything from the beginning of $pagelinks up to the first title $newlinks .= substr($pagelinks, 0, $pagenames[0][1]); } else { // Start at the previous offset + title length (the beginning of the next group of HTML tags) $start = $pagenames[$i - 1][1] + $pagenames[$i - 1][2]; $length = $pagenames[$i][1] - $start; // Adds everything between the last title and the beginning of this one $newlinks .= substr($pagelinks, $start, $length); } // Adds the new HTML-formatted page title $newlinks .= $pagenames[$i][0]; // On the last loop, add the last group of HTML tags if ($i == count($pagenames) - 1) { // Start at the current offset + title length $start = $pagenames[$i][1] + $pagenames[$i][2]; $newlinks .= substr($pagelinks, $start); } } // Hooray! $newlinks is ready. Insert wherever. if ($method) return $newlinks; else echo $newlinks; } ?>