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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:37:04+00:00 2026-05-26T10:37:04+00:00

Me and several friends taking the same programming course have been confused by this

  • 0

Me and several friends taking the same programming course have been confused by this for hours so far, hopefully someone here can help.
The aim is to take a list of urls, split by new lines, prepend [ img] and append [/ img] for each URL, as suitable for a bulletin board. The actual code includes a switch to allow for both [ img] and [ thumb] bbcodes, but both have the same effect.
Instead of outputting

[ img]1[/ img]
[ img]2[/ img]

it outputs

[ img]1
2[ /img]

The same happens for any number of URLs. Here’s the code I am using.

   <?php

    $url_f = (isset($_POST['text'])) ? $_POST['text'] : false;
    $thumb = (isset($_POST['type'])) ? $_POST['type'] : false;
    $urls = ($url_f) ? explode('\n',$url_f) : '';

    ?>

    <textarea rows='20' cols='40' readonly='1'>


    <?php
    switch ($thumb){
        case 'img':
            for ($i = count($urls)-1; $i >= 0; $i--)
            {
                echo "[img]". $urls[$i] ."[/img]\n";
            }
            break;

        default:
            break;

        case 'thumb':
            for ($i = count($urls)-1; $i >= 0; $i--)
            {
                echo '[thumb]'. $urls[$i] ."[/thumb]\n";
            }
            break;

    }

    ?>

    </textarea>
  • 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-26T10:37:05+00:00Added an answer on May 26, 2026 at 10:37 am


    There are three different types of newlines: \r, \n, and \r\n. I don’t do much web development, but different OSes will still probably send different newlines, so you’ll have to do some checking to find out what character(s) to split with.

    In your code, since \n isn’t working, the newline is probably \r\n or \r.

    Edit: The single quoted string literal may be the problem.

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

Sidebar

Related Questions

Friends, My apex page has several different radio groups, each one can have the
I use several different programming languages every day, and I'd like to have different
I have several apps that I work on and like to distribute to friends
I've had several clients ask this, and I've never been able to get or
Several questions about accessor methods in C++ have been asked on SO, but none
Several of my controller actions have a standard set of failure-handling behavior. In general,
Several times throughout the course of our current project, the visual studio designer has
Several of my overriden Equals methods have started throwing Invalid Cast Exceptions - Unable
Several databases I've been looking at recently implement a virtual machine internally to perform
For several applications I made for my current client I have shared user accounts.

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.