creating a ul from php submitted links

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • brewthom
    New Member
    • Dec 2006
    • 5

    creating a ul from php submitted links

    I'm trying to make a ul from submitted websites. I've got the links to work, but can't figure out how to make them appear in a list. I'm writing this to a text file, not a database. Thanks and Happy New Year!




    <?php
    $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
    for($i = 0; $i < count($text); $i++)
    {
    $web = $text[$i];
    }
    ?>

    <li><a href="http://<?php echo $web;?>" target="_blank" ><?php echo $web;?></a></li>
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    Originally posted by brewthom
    I'm trying to make a ul from submitted websites. I've got the links to work, but can't figure out how to make them appear in a list. I'm writing this to a text file, not a database. Thanks and Happy New Year!

    <?php
    $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
    for($i = 0; $i < count($text); $i++)
    {
    $web = $text[$i];
    }
    ?>

    <li><a href="http://<?php echo $web;?>" target="_blank" ><?php echo $web;?></a></li>
    You must start a list with the <ul>, <ol> or <dl> definitions (and close them of course). See the next code:[php]<?php
    $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
    echo '<ul>'; <==== START THE LIST
    for($i = 0; $i < count($text); $i++) {
    $web = $text[$i];
    }
    ?>
    <li><a href="http://<?php echo $web;?>" target="_blank" ><?php echo $web;?></a></li>
    </ul> <==== END THE LIST[/php]
    Ronald :cool:

    Comment

    • brewthom
      New Member
      • Dec 2006
      • 5

      #3
      Thanks Ronald. I've got the code working, but what it isn't doing is making a list. It's just replacing the preceeding item. (I have the file set to append) I'm new to php, so there is probably something very simple I'm missing. Would this be easier with a database? Seems like a simple enough idea. Here's the code:

      ----------------
      <?php

      $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
      echo '<ul>';

      //start list


      for($i = 0; $i < count($text); $i++)
      {

      $web = $text[$i];

      }

      ?>


      <li><a href="http://<?php echo $web;?>" target="_blank" ><?php echo $web;?></a></li>
      </ul>


      </div><!--end left urls-->




      Originally posted by ronverdonk
      You must start a list with the <ul>, <ol> or <dl> definitions (and close them of course). See the next code:[php]<?php
      $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
      echo '<ul>'; <==== START THE LIST
      for($i = 0; $i < count($text); $i++) {
      $web = $text[$i];
      }
      ?>
      <li><a href="http://<?php echo $web;?>" target="_blank" ><?php echo $web;?></a></li>
      </ul> <==== END THE LIST[/php]
      Ronald :cool:

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        In order to concatenate all entries into the $web variable, you must specify
        Code:
        $web .= $text[$i]
        If you want to make every $text[$i} item an <a>... link, you must NOT concatenate the $web variable, but place the current <a.. statement within the loop. SO if you want all extracted links in a clickable list of sites, you can use this code:
        [php]<?php
        $text = (file("http://www.brewerthomp son.com/classes/class/309/multiurl.txt")) ;
        echo '<ul>';
        //start list
        for($i = 0; $i < count($text); $i++) {
        $name=trim($tex t[$i]); // remove newline chars and blanks
        echo "<li><a href='http://".$name."' target='_blank' >".$name."</a></li>";
        }
        ?>
        </ul>
        </div><!--end left urls-->[/php]

        To be sure that it is an array you get back from your remote site, print out the $text array before you go into the loop. Like this
        Code:
        echo '<pre>'; print_r($text);
        It will show you the exact content of that $text array (when it is not an array you will see that also).

        Ronald :cool:

        Comment

        • brewthom
          New Member
          • Dec 2006
          • 5

          #5
          Thanks Ronald! I've got it now. This is one of the most helpful forums I've found! Have a great New Years!



          [QUOTE=ronverdon k]In order to concatenate all entries into the $web variable, you must specify
          Code:
          $web .= $text[$i]
          If you want to make every $text[$i} item an <a>... link, you must NOT concatenate the $web variable, but place the current <a.. statement within the loop. SO...

          Comment

          • ronverdonk
            Recognized Expert Specialist
            • Jul 2006
            • 4259

            #6
            Glad we could help. Hope to see you again.

            Ronald :cool:

            Comment

            Working...