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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:13:06+00:00 2026-06-15T04:13:06+00:00

Is it possible use str_replace() and use function in replace? $value = gal($data); $replace

  • 0

Is it possible use str_replace() and use function in replace?

$value = "gal($data)";

$replace = str_replace($dat, $value, $string);

gal($data) is a function and I need replace one code for this function and show, but the script only give me finally this gal($data), and the function no show nothing

Is it possible use str_replace() for replace code and replace by the function or some similar method?

  • 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-06-15T04:13:07+00:00Added an answer on June 15, 2026 at 4:13 am

    PHP has a function called preg_replace_callback that does this. When you pass it a callback function, it will pass each match through your function. You can choose to replace, based upon the matched value, or ignore it.

    As an example, suppose I have a pattern that matches various strings, such as [a-z]+. I may not want to replace every instance with the same value, so I can call a function upon eat match found, and determine how I ought to respond:

    function callback ($match) {
        if ($match[0] === "Jonathan")
            return "Superman";
        return $match[0];
    }
    
    $subject = "This is about Jonathan.";
    $pattern = "/[a-z]+/i";
    $results = preg_replace_callback($pattern, "callback", $subject);
    
    // This is about Superman.
    echo $results;
    

    Note in our callback function how I am able to return special values for certain matches, and not all matches.

    Expanding Abbreviations

    Another example would be a lookup. Suppose we wanted to find abbreviations of programming languages, and replace them with their full titles. We may have an array that has abbreviations as keys, with long-names as values. We could then use our callback ability to lookup the full-length names:

    function lookup ($match) {
        $langs = Array(
            "JS"  => "JavaScript", 
            "CSS" => "Cascading Style Sheets", 
            "JSP" => "Java Server Pages"
        );
        return $langs[$match[0]] ?: $match[0];
    }
    
    $subject = "Does anybody know JS? Or CSS maybe? What about PHP?";
    $pattern = "/(js|css|jsp)/i";
    $results = preg_replace_callback($pattern, "lookup", $subject);
    
    // Does anybody know JavaScript? Or Cascading Style Sheets maybe? What about PHP?
    echo $results;
    

    So every time our regular expression finds a match, it passes the match through lookup, and we can return the appropriate value, or the original value.

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

Sidebar

Related Questions

Is it possible to use array_map in conjunction with str_replace without calling another function
Using sprintf() how can I replace multiple placeholders in a string with one value?
Possible Duplicate: Java isEmpty() undefined for String? I copied my code from one java
Is it possible use a MySQL query to perform this kind of check? If
I need a control having these features: It should be possible use it in
Is this possible to use Ajax.Beginform with update target inside of ajax form. like
Possible Duplicate: split a string in python I want to change this: str =
Possible Duplicate: Why use iterators instead of array indices? string::iterator it; for (it =
Possible Duplicate: Process escape sequences in a string in Python If I get this
In PHP programming can we use str_replace(); in echo ''; If it is possible

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.