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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:19:11+00:00 2026-05-28T14:19:11+00:00

I have a large string variable that is assigned from a database column of

  • 0

I have a large string variable that is assigned from a database column of type “Text” with Collation latin_swedish_ci.

Because it is in ASCII, I need to replace all non UTF-8 characters before I can put variable into my PDF generation script.

As we all know, the standards used by PDF are evil. If I use plain ASCII input it will go insane and cause a rip in space-time.

So in order to prevent anymore damage to our universe, I need help figuring out why this str_replace() function is only replacing one of a character type and ignoring any repeats of this character

Here is my code:

$tc = str_replace (array("\n", "£", "&"), array("<br/>", "&pound;", "&amp;"), $tc);

Input:

Terms & Conditions: Mandatory charge of £10 for cancellations.    
VAT E&EO

Output:

Terms &amp; Conditions: Mandatory charge of &pound;10 for cancellations.
VAT E&EO

As you can see in the output on the second line the str_replace() does not change the ampersand character.

I wonder if this is because its over two lines or something like that.

So any idea how to get the function to work as I want it to, otherwise well your going to wake up with many Micro Blackholes vanishing your bowl of cereal tomorrow.

  • 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-28T14:19:12+00:00Added an answer on May 28, 2026 at 2:19 pm

    It looks like what you are trying to achieve could be done using these 2 functions:

    nl2br(htmlentities($tc));
    

    The benefit being that if your $tc variables gets any more HTML entities in the future, you won’t have to fiddle with your str_replace().

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

Sidebar

Related Questions

I have a arbitrarily large string of text from the user that needs to
I have a unit test that is used to test variable conversions from string
In entity framework I have an Entity 'Client' that was generated from a database.
I have a code meant to strim a string within a large text file.
I have a text file stored as a string variable. The text file is
Hi I have a string variable with large content. I have to remove unwanted
I have a method that retrieves data from a json serialized string and writes
I have a large string, similar to this one: BREW pot HTCPCP/1.0 Accept-Additions: #milk;3#whiskey;splash
I have a large string I need to parse, and I need to find
I have a large file(60mb) and I am reading the file into a string

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.