www.webdeveloper.com
Results 1 to 5 of 5

Thread: implement a function sort horizontal in php

  1. #1
    Join Date
    Aug 2007
    Posts
    11

    implement a function sort horizontal in php

    How can I implement the below example wherein the desired results would be like this in php format

    Text

    text | text | text | text | text | More...

    Text2

    text | text | text | text | text | More...

    Text 3

    text | text | text | text | text | More...

    Note: Only the first five words will be visible with the More link as the sixth. All text will be clickable as links.

    thanks

  2. #2
    Join Date
    Jan 2005
    Location
    Alicante (Spain)
    Posts
    7,742
    Quote Originally Posted by eyeshield21
    in php format
    ???
    Quote Originally Posted by eyeshield21
    All text will be clickable as links.
    What do you mean?

  3. #3
    Join Date
    Mar 2007
    Location
    Athens, Greece
    Posts
    177
    Hello,

    @bokeh: I think URL links separated by the pipe "|" sumbol (like the ones in your signature)

    eg: Home| SiteMap | News | Contact etc..

    An example php script that automatically creates the following links:

    Visit Home | View SiteMap | Read News | Contact Us

    PHP Code:
    <?php 

    //Set your site
    $Domain="http://www.yoursite.com/";  

    //The locations or files in your site
    $URIs=array("Home/""SiteMap.html" "News/""Contact.php"); 

    //The visible link-names in your html (or php) doc. What should be between <a href=..> and  </a>
    $URLS_Descriptions=array("Visit Home""View SiteMap""Read News""Contuct Us");  

    $Output="";

    for (
    $i=0;$i<count($URIs);$i++) {
      
    $Delimiter=($i<count($URIs)-1)?" | ":"";  // The visible separator (here is the "|") of your links. 
      
    $Output.='<a href="' .$Domain.$URIs[$i]. '" target="_self"  title=" Click to '.$URLS_Descriptions[$i].' ">'.$URLS_Descriptions[$i].'</a> '."\n".$Delimiter;
    }

    echo 
    $Output."\n<br><br>\n";  //Print the total string (and a couple of newlines)

    ?>
    Kostas

  4. #4
    Join Date
    Mar 2007
    Location
    Athens, Greece
    Posts
    177
    A bit different code (one array is used to store the link-path couples) used to "auto create" the working links shown in the previous post [you can add more, remove or replace the names (links) and destinations (paths) to reflect your needs]:

    PHP Code:
    <?php
    //Set your site
    $Domain="http://www.yoursite.com/";  

    //An associative array of links and their (relative paths) locations or files  
    $URLs=array("Visit Home" => "Home/""View SiteMap" => "SiteMap.html""Read News" => "News/""Contact Us" => "Contact.php");

    $Output="";
    $Counter=0;

    foreach (
    $URLs as $Link => $URI) {
      
    $Counter++;
      
    $Delimiter=($Counter<count($URLs))?" | ":"";  // The visible separator (here is the "|")  of your links. 
      
    $Output.='<a href="' .$Domain.$URI'" target="_self"  title=" Click to '.$Link.' ">'.$Link.'</a> '."\n".$Delimiter;
    }

    echo 
    $Output."\n<br><br>\n";  //Print the total string (and a couple of newlines)
    ?>
    The script automatically creates the following links (below links are not active here):
    Visit Home | View SiteMap | Read News | Contact Us

    Kostas
    Last edited by Kostas Zotos; 09-17-2007 at 10:22 PM.

  5. #5
    Join Date
    Aug 2007
    Posts
    11
    thanks for the response Kostas Zotos it really helps me, now what if the out put
    is like this:

    eg:

    Cat

    subcat | subcat2 | subcat3 | subcat4| subcat5

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles