I was thinking something more along the lines of this:
function getTextBetweenTags($string, $tagname, $lang) {
$db = new Database(DB_SERVER, DB_USER, DB_PASS, DB_DATABASE);
$db->connect();
$pattern = "/<$tagname ?.*>(.*)<\/$tagname>/";
preg_match($pattern, $string, $matches);
$sql= "SELECT * FROM navigation, pages WHERE navigation.navigationID = '$matches[1]' AND navigation.pageID = pages.pageID";
$rows = $db->query($sql);
while ($record = $db->fetch_array($rows)) {
$newtext = "http://www.mydomain.com/".$lang."/".$record[navigationID]."/".str_replace(" ", "_", $record[linkname]);
}
return $newtext;
}
$str = '<p align="left">Go To This <a href="<navigation>3</navigation>">Page</a>.</p><p>This <a href="<navigation>4</navigation>">Page</a> is also good.</p>';
$txt = getTextBetweenTags($str, "navigation", "en");
echo $txt;
Which returns "http://mydomain.com/en/4/My_Link_Name"
I want it to return "Go To This Page. This Page is also good." With the words "Page" linked with the properly formatted url.
I think im missing incorporating an str_replace here somehow so i return the properly formatted urls and the rest of the string where applicable. Hope im making some sort of sense here.