shaneg55 Posted September 9, 2010 Share Posted September 9, 2010 how can i find reference to something like this "navigationID=3" or "navigationID=44" within a string and then re write it to become something like this "/en/content/3/Link_Name"? there could be more than one reference within the string and the integer val (ie 3 and or 44) will not be known. Any help with this would be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Vince889 Posted September 9, 2010 Share Posted September 9, 2010 how can i find reference to something like this "navigationID=3" or "navigationID=44" within a string and then re write it to become something like this "/en/content/3/Link_Name"? there could be more than one reference within the string and the integer val (ie 3 and or 44) will not be known. Any help with this would be greatly appreciated. Regex would help, but if you want to use str_replace, thats fine. $string = "blahblah navigationID=44"; $replacement = "/en/content/3/Link_Name"; echo str_replace("navigationID=44",$replacement,$string); Atleast I think thats what you want... Quote Link to comment Share on other sites More sharing options...
shaneg55 Posted September 10, 2010 Author Share Posted September 10, 2010 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. Quote Link to comment Share on other sites More sharing options...
shaneg55 Posted September 10, 2010 Author Share Posted September 10, 2010 Still no thoughts on this from anyone? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.