lszanto Posted June 9, 2007 Share Posted June 9, 2007 Hey, I've been writing a small script that puts some data sent from a form into a webpage e.g title, header, nav. And in this I have to convert links from this: home_home.html,about_about.html,links_links.html to this: <a href="home.html" >home</a>   <a href="about.html" >about</a>   <a href="links.html" >links</a>   That bit was not to hard to do, but now my problem is I can't convert them back from html into the original link format, does anybody have any ideas? This is how far I got, all it does is counts the amount of links that are in the page. //Explode by .html, counting the links. $linknum = explode(".html", $links); //Count links. $linknum = count($linknum) - 1; If it helps this is the bit that turns them into links. //Explode links, set num var. $links = explode(",", $links); //Run links array exploding them further. foreach($links as $link) { //Explode individual link. $linkparts = explode("_", $link); //Make url. $url .= $linkparts[1] . "_"; //Make link names. $linkos .= $linkparts[0] . "_"; } //Explode links and urls into parts. $urls = explode("_", $url); $links = explode("_", $linkos); //Count the array. $num = count($urls); $num--; //Run loop showing links. for($i = 0; $i < $num; $i++) { //Show the link. $towrite .= "<a href=\"$urls[$i]\" >$links[$i]</a>  \n"; } Please help if you can and thanks in advance. Link to comment https://forums.phpfreaks.com/topic/54863-link-conversions/ Share on other sites More sharing options...
chigley Posted June 9, 2007 Share Posted June 9, 2007 <?php $string = "home_home.html,about_about.html,links_links.html"; $urls = explode(",", $string); foreach($urls as $url) { $pieces = explode("_", $url); $urltext = $pieces[0]; $urlurl = $pieces[1]; echo "<a href=\"{$urlurl}\">{$urltext}</a>"; } ?> Link to comment https://forums.phpfreaks.com/topic/54863-link-conversions/#findComment-271322 Share on other sites More sharing options...
lszanto Posted June 9, 2007 Author Share Posted June 9, 2007 Thats the part I've already done, I just need to know how to convert from html links back to the shortened version of home_home.html e.g. Link to comment https://forums.phpfreaks.com/topic/54863-link-conversions/#findComment-271549 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.