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 6962905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T15:43:13+00:00 2026-05-27T15:43:13+00:00

here is my working php explode code for NON links: <?php $textarea = get_custom_field(‘my_custom_output’);

  • 0

here is my working php explode code for NON links:

<?php
            $textarea = get_custom_field('my_custom_output');
            $array = explode(',',$textarea);
            $output = ''; // initialize the variable
            foreach ($array as $item) {
               $item = trim($item); // clear off white-space
               $output .= '<li>' . $item . '</li>';
            }


?>

            <ul>
            <?php print $output; ?>
            </ul>

..and the code which defines “my_custom_output”, which I input into my textarea field:

text1,text2,text3,etc

..and the finished product:

  • text1
  • text2
  • text3
  • etc

So that works.
Now what I want to do is make text1 be a link to mywebsite.com/text1-page-url/

I was able to get this far:

<?php
            $textarea = get_custom_field('my_custom_output');
            $array = explode(',',$textarea);
            $output = ''; // initialize the variable
            foreach ($array as $item) {
               $item = trim($item); // clear off white-space
               $output .= '<li class="link-class"><a title="' . $item . '" href="http://mywebsite.com/' . $item_links . '">' . $item . '</a></li>';
            }


?>

            <ul>
            <?php print $output; ?>
            </ul>

Now, I would like $item_links to define just the rest of the url. For example:
I want to put input this into my textarea:

text1:text1-page-url,text2:new-text2-page,text3:different-page-text3

and have the output be this:

  • text1
  • text2
  • ..etc (stackoverflow forced me to only have two links in this post because I only have 0 reputation)

another thing I want to do is change commas to new lines. I know the code for a new line is \n but I do not know how to swap it out. That way I can put this:

text1:text1-page-url
text2:new-text2-page
text3:different-page-text3

I hope I made this easy for you to understand. I am almost there, I am just stuck. Please help. Thank you!

  • 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-27T15:43:13+00:00Added an answer on May 27, 2026 at 3:43 pm

    Just split the $item inside your loop with explode():

    <?php
    $separator1 = "\n";
    $separator2 = ":";
    $textarea = get_custom_field('my_custom_output');
    $array = explode($separator1,$textarea);
    $output = ''; // initialize the variable
    foreach ($array as $item) {
        list($item_text, $item_links) = explode($separator2, trim($item));
        $output .= '<li class="link-class"><a title="' . $item_text . '" href="http://mywebsite.com/' . $item_links . '">' . $item_text . '</a></li>';
    }
    ?>
    
    <ul>
    <?php print $output; ?>
    </ul>
    

    And choose your string separators so $item_text, $item_links wouldn’t contain them.

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

Sidebar

Related Questions

I'm working with PHP 5 here. I have the following code: $data = json_decode($_POST['data']);
Here's the XML file i'm working on: <list> <activity>swimming</activity> <activity>running</activity> <activity>soccer</activity> </list> The index.php,
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's
Here's the XML code I'm working with: <inventory> <drink> <lemonade supplier=mother id=1> <price>$2.50</price> <amount>20</amount>
I am working on PHP. I was working with MySQL before. Here is the
I'm working in PHP with friendly URL paths in the form of: /2011/09/here-is-the-title /2011/09/here-is-the-title/2
I am working in PHP with array iteration. I have a multidimensional array like
PHP developer here working with c#. I'm using a technique to remove a block
Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir , but I
I am trying to center a div button and its not working here is

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.