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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T09:38:55+00:00 2026-05-15T09:38:55+00:00

Am trying to use something like: $newdata = preg_replace($pattern, $replacement, $data); Now my replacement

  • 0

Am trying to use something like:

$newdata = preg_replace($pattern, $replacement, $data);

Now my replacement is something like

$pattern = "/START(.*?)END/is";
$replacement = "START $config END";

Now, $config contains contents like

array('Test\\\'s Page')

The problem is that after I write the content, $newdata becomes

START array('Test\\'s Page') END

As you see above a single \ goes missing because it gets evaluated. How do I avoid that?

  • 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-15T09:38:56+00:00Added an answer on May 15, 2026 at 9:38 am

    This works as expected… at least according to the manual of preg_replace.

    To use backslash in replacement, it must be doubled (“\\\\” PHP string).

    This is needed as you can use \\n for back references. If you don’t want a back reference but want the \ itself you need to escape it. If you want 3 backslashes you must write 6 backslashes.

    $data = 'Some START END testdata';
    $config = 'array(\'Test\\\\\\\\\\\\\'s Page\')';
    $replacement = "START $config END";
    $pattern = "/START(.*?)END/is";
    var_dump($data, $config, $replacement, $pattern);
    $newdata = preg_replace($pattern, $replacement, $data);
    var_dump($newdata);
    

    This will generate the following output.

    string(23) "Some START END testdata"
    string(26) "array('Test\\\\\\'s Page')"
    string(36) "START array('Test\\\\\\'s Page') END"
    string(17) "/START(.*?)END/is"
    string(47) "Some START array('Test\\\'s Page') END testdata"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use jQuery with MYSQL and I wrote something like this
I am trying to use a malloc of short, something like typedef union _SOME_STRUCT_
I was trying to do something like Google's Adsense. I believe they use javascript?
i'm trying to create a Dynamic Sub-menu to use it in Wordpress, Something like
Trying to use something like the below with a char array but it doesn't
I'm trying to use something like a compass, passing it longitude/latitude values to let
I'm trying to use something like listId.Items.Remove(listId.SelectedItem[x]); after each item has been processed. Obviously
I'm trying to use strlen or something like that to count multiple set of
I'm trying to use something along the lines of unexpand -t 4 *.php but
I am trying to use NSXMLParser to parse an XML file that looks something

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.