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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:47:39+00:00 2026-05-25T11:47:39+00:00

Ok, reading a file using file_get_contents and removing <?php , <? , and/or any

  • 0

Ok, reading a file using file_get_contents and removing <?php, <?, and/or any ?> tags, but I also want to remove all line breaks within the file. How can I achieve this?

For example a file like so:

<?php

$txt['dpmod_testing'] = 'Testing';
$txt['dpmodtitle_testing'] = 'My Testing Module';
$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';
$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';

?>

Should return this:

$txt['dpmod_testing'] = 'Testing';
$txt['dpmodtitle_testing'] = 'My Testing Module';
$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';
$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';

But instead I am getting this written to the file, when using file_put_contents:

$txt['dpmod_testing'] = 'Testing';

$txt['dpmodtitle_testing'] = 'My Testing Module';

$txt['dpmodinfo_testing'] = 'Just a Testing Module, nothing special.';

$txt['dpmoddesc_testing'] = 'Here is a description for this testing module that you will see within the Add Modules section![color=red]I can give myself credit for this module if I want to![/color][hr]And this text string also accepts BBC Code!';

With 2 line breaks above and 2 line breaks also below. How can I remove all of these line breaks?

Here is the preg_replace I am using to remove the php tags from within the file, but how can this be modified to also keep the file the way it is, and remove all line breaks?

preg_replace(array('/<\?php/s', '/\?>/s', '/<\?/s'), array('', '', ''), $str);

Thanks guys 🙂

  • 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-25T11:47:40+00:00Added an answer on May 25, 2026 at 11:47 am

    like written in

    Removing redundant line breaks with regular expressions

    you could probably add ‘(?:(?:\r\n|\r|\n)\s*){2}/s’ and ” to your arrays
    ..but I did not check

    just make sure ich matches new line twice only

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

Sidebar

Related Questions

I'm reading a file using bufferedreader, so lets say i have line = br.readLine();
When reading lines from a text file using python, the end-line character often needs
I'm reading a rss feed using simple code: <?php $homepage = file_get_contents('http://www.forbes.com/news/index.xml'); $movies =
I have .zip file which contain csv data. I am reading .zip file using
I'm Using FILE * F opened in _sfopen () I'm reading from the file
I'm reading a local file using a BufferedReader wrapped around a FileReader: BufferedReader reader
I am reading an xml file using javascript and then I need to submit
I've tried reading a JPG file using the StreamReader class' ReadToEnd() method which returns
I am reading a very large file using a NSInputStream and sending them to
I am reading the contents of the file using fread into an char array.

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.