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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T02:21:50+00:00 2026-06-19T02:21:50+00:00

Probably a simple problem here, but I cannot find it. I am exploding a

  • 0

Probably a simple problem here, but I cannot find it.

I am exploding a string that was input and stored from a textarea. I use nl2br() so that I can explode the string by the <br /> tag.

The string explodes properly, but when I try to get the first character of the string in a while loop, it only returns on the first line.

Note: The concept here is greentexting, so if you are familiar with that then you will see what I am trying to do. If you are not, I put a brief description below the code sample.

Code:

while($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
$comment = nl2br($row['comment']);
$sepcomment = explode("<br />", $comment);
$countcomment = count($sepcomment);
$i = 0;



//BEGIN GREENTEXT COLORING LOOP
while($i < $countcomment) {

$fb = $sepcomment[$i];
$z = $fb[0]; // Check to see if first character is >

if ($z == ">") {
$tcolor = "#789922";
}
else {
$tcolor = "#000000";
}

echo '<font color="' . $tcolor . '">' . $sepcomment[$i] . '</font><br>';

$i++;
}
//END GREENTEXT COLORING LOOP


}

Greentext: If the first character of the line is ‘>’ then the color of that entire line becomes green. If not, then the color is black.

Picture: Picture of output

What I have tried:

  1. strip_tags() – Thinking that possibly the
    tags were acting as the first characters.
  2. $fb = preg_replace("/(<br\s*\/?>\s*)+/", "", $sepcomment[$i]);
  3. str_replace()
  4. echo $z //Shows the correct character on first line, blank on following lines.
  5. $z = substr($fb, 0, 1);

Here is a test I just did where I returned the first 5 characters of the string.
first 5 characters

Any ideas for getting rid of those empty characters?

  • 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-06-19T02:21:51+00:00Added an answer on June 19, 2026 at 2:21 am

    Try “trim” function

    $fb = trim($sepcomment[$i]);
    

    http://php.net/manual/en/function.trim.php

    (probably line breaks are the problem, there are \n\r characters after tag)

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

Sidebar

Related Questions

Probably a simple problem here, but this is my use case: Need to see
My problem is probably rather simple, but I'm not at that skill level yet.
I'm probably missing something simple here, but I can't find the answer elsewhere. I
new to programmation, im learning and here is probably a very simple problem for
I've got probably what is a simple problem, but there's no informative errors or
The problem is probably quite simple. $q = SELECT id FROM users WHERE name
Probably something simple, but heres my problem, I have implememnted a simple captcha into
There is probably a simple answer for this, but I couldn't find one, so
This is probably quite simple but I've googled and can't find an answer. I
This is probably a simple/dumb problem. I can't find any documentation on it. I

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.