Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 963137
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:37:42+00:00 2026-05-16T01:37:42+00:00

I’m creating a user input where I want them to list links as well

  • 0

I’m creating a user input where I want them to list links as well as descriptions.

Doing this from scratch, so I’m open to sytax suggestions. I was thinking of something like this:

www.ebay.com | "my Ebay" , http://www.craigslist.org?s=bla | "Craiglist" ,
www.twitter.com/ev | "My Twitter"

I’d like to convert this into an UL with php. I think I would use a for each but wanted to see what the best way to go about this would be.

so goals:

  1. Grab URL, if HTTP is append it, take it off
  2. Grab Description
  3. Create link, similar to this

    <a href="http://<?php echo $link; ?>"><?php echo $desc; ?></a></li>
    
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:37:42+00:00Added an answer on May 16, 2026 at 1:37 am
    $data = explode(",", $string);
    $list = "<ul>";
    foreach ($data as $item) {
        list($website, $title) = explode("|", $item);
    
        // Clean up the extra white spaces, if any.
        $website = trim($website);
        $title = trim($title);
    
        // make lowercase for the below check
        $website = strtolower($website); 
    
        // if website does not have http:// append it
        $website = (strpos($website, "http://") !== 0)?"http://" . $website:$website;
    
        $title = str_replace('"', "", $title); // optional, but incase you do not want the quotes. 
        //If you do want them, then I would suggest htmlspecialchars so it does not mess up the title attribute below.
        $list .= '<li><a href="' . $website . '" title="' . $title . '">' . $title . '</a></li>';
    }
    
    $list .= '</ul>';
    echo $list;
    

    Should get you to where you want to be.

    Update
    Note the quote remark, it will break the html. Solution, remove the quotes as shown with str_replace or replace them with their html counter part using htmlspecialchars().

    Update

    Added a check for http:// in the url at the first position, if it is not there it will be appended. I used strpos() to do a simple check.

    Also added trim and removed the spaces around , and the | characters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.