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

  • Home
  • SEARCH
  • 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 8264267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:23:39+00:00 2026-06-08T04:23:39+00:00

I am writing a webpage that involves using a php array of strings to

  • 0

I am writing a webpage that involves using a php array of strings to output a js array as follows

while($main2row = mysqli_fetch_assoc($result)) {
$tSummary[$main2row['id']] = '"'.$main2row['content'].'"';

    $tTitle[$main2row['id']] = '"'.$main2row['title'].'"';

}

//the above gets the php from the sql database, then stores it in an array, both are string arrays

foreach ( $tSummary as $key => $val) 
{

echo "summArray['".$key."'] = ".nl2br($val).";\n"; 

} 

foreach ( $tTitle as $key => $val) 

{ 

echo "titleArray['".$key."'] = ".nl2br($val).";\n"; 

} 
//these foreach loops will print in a js script and will store the php arrays as js arrays

I know I should probably be using json but this is the way it was set up for me by someone else and I feel like I should adhere to their code.

The PROBLEM is that when the data is stored, it fails in the following way:

summArray['225594172793552897'] = "      blah blah blah blah blah - blah.<br />
<br />
       blah blah blah blah.....";  /* this one is messed up */

summArray['225595300046307328'] = "text text text text text text text text text text text text text text ."; /* this one is fine */

I notice that the string breaks wherever there is a line break so i tried to use nl2br but, while that added a br tag, it did not remove the line break. is there any way I can get rid of this line break?

  • 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-08T04:23:41+00:00Added an answer on June 8, 2026 at 4:23 am

    Instead of nl2br($val), try str_replace("\n", "\\n", $val) to get newlines in JavaScript, or str_replace("\n", "\\n", nl2br($val)) to get HTML linebreaks as well.

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

Sidebar

Related Questions

I'm writing a project in php that will basically give me a webpage with
I am writing a web page that uses some php files. The php isn't
I'm writing a webpage that relies on an external javascript file (that I have
I'm writing a Firefox add-on that do something after the webpage is completely loaded.
I'm writing a webpage that has a table with rows that slide open and
I am writing some functionality using jQuery that i normally handle with a page
I am writing a Firefox addon that allows for annotating a webpage by adding
I'm writing a small webpage that will enable students to answer questions and get
I'm writing a simple Python CGI script that grabs a webpage and displays the
I'm writing a basic crawler that simply caches pages with PHP. All it does

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.