Jump to content

Link conversions.


lszanto

Recommended Posts

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> &nbsp
<a href="about.html" >about</a> &nbsp
<a href="links.html" >links</a> &nbsp

 

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> &nbsp\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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.