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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:35:53+00:00 2026-05-26T04:35:53+00:00

I am quite familiar with sed on bash shell, so I do cat $myfile

  • 0

I am quite familiar with sed on bash shell, so I do

cat $myfile | egrep $pattern | sed -e 's/$pattern/$replace/g'

a lot. Quite a few times, I find that I need to do similar kind of “string parsing” inside PHP.

So my question is simple, what is the equivalent of sed -e 's/$pattern/$replace/g' in PHP ?

I know preg_match , preg_replace , but I haven’t used them / not at all familiar with them. I would really appreciate sample code in PHP. (converting say a $var = '_myString' to $newVar = 'getMyString' )

  • 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-26T04:35:54+00:00Added an answer on May 26, 2026 at 4:35 am

    The preg_ functions uses the same regexp library that Perl does, so you should be at home. There’s documentation of the syntax here.

    For example:

    sed -e 's/$pattern/$replace/g'
    

    Would be something like:

    $output = preg_replace("/".$pattern."/", $replace, $input);
    

    The most common is to use / as delimiter, but you can use other characters, which can be useful if the pattern contains lots of slashes, as is the case with urls and xml tags. You may also find preg_quote useful.

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

Sidebar

Related Questions

I'm not all that familiar with jquery so I'm not quite sure how to
Having studied Java at school I am quite familiar with the DAO-pattern( Data access
I have been in this situation quite a few times where visual studio does
I am quite familiar with ASP.NET MVC and know that a controller’s method can
Now that I am quite familiar with Python, decided to learn C++, so I
i am quite familiar with Smarty and recently decided to use Zend framework in
I consider myself quite fluent in PHP and am rather familiar with nearly all
Quite a few comments to answers in a different post, Where are the best
I'm not quite familiar with asp.net ajax, so my question might be a silly
I'm quite familiar with the System.Diagnostics.Process class. But, I'm wondering about how I can

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.