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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:18:35+00:00 2026-05-28T05:18:35+00:00

I have a php script that is reading a file in (file_get_contents). I want

  • 0

I have a php script that is reading a file in (file_get_contents). I want to replace all newlines with br’s, and strip out all other characters. However, I am getting an error when interpreting the contents into a javascript variable.

I think the guilty party is the “^Z” character, but I don’t know how to get rid of it. The “^M” is a git character, and I believe the “^Z” is actually part of the string itself.

How would I strip this character out in php?

enter image description here


Okay, my question was wrong before, so I have updated it with new content.

How do I ensure that all newlines are removed from a php string? This string is read in with file_get_contents, then javascript is dynamically created with the contents of the file. The “\n” is replaced with “NEW,” and the “\r” is replaced with “”.

However, I am getting an “Unexpected EOF” error, and when I copy the string and paste it into the console, something is giving me newlines. How do I make sure that ALL newlines (whitespace for that matter) is trimmed out?

trim()
str_replace
preg_replace

Have all been used, any help is greatly appreciated!

SyntaxError: Unexpected EOF

  • 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-28T05:18:36+00:00Added an answer on May 28, 2026 at 5:18 am

    CTRL-Z is the DOS/Windows end-of-file character for text files. If you examine your input file, you’ll probably find that character in there.

    It stems from the earliest days (CP/M no less) when files were an exact multiple of the disk sector size so you couldn’t have files that weren’t a multiple of that.

    So, if you wanted to end the file earlier, you placed a special end-of-file character in there that the file reading routines would understand. This wasn’t really a problem for binary files since it didn’t matter if they had extraneous information at the end – it would most likely be ignored. However, you _didn’t want any rubbish at the end of your nice little WordStar 3.3 document.

    The ^Z character is code number 26 so you should be able to use str_replace with the \x1a character, something like:

    $str = str_replace ("\x1a", "", $str);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php script that is reading a remote CSV file, and adding
I have a PHP script that initialises an image gallery. It loops through all
I have a PHP script that processes file uploads. The script tries to organise
I have a PHP script that pushes the headers to allow a file to
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
I have a PHP CLI script, that processes a csv file, inserting it's content
So I have a php script, I want to read in a file line
I have php script that creates a temporary watermark image for users that are
I have a PHP script that runs as a CGI program and the HTTP
I have a PHP script that needs to determine if it's been executed via

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.