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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:14:34+00:00 2026-05-25T00:14:34+00:00

If I have a string, and I search in the string for a particular

  • 0

If I have a string, and I search in the string for a particular text after a signal, is there any way to output the text string with the particular text after the signal replaced with a variable of the same name?

Example

I have

$strin="This is #fruit"
$fruit="omg"

So I search $strin, extract “fruit” using regex, then replace #fruit with the value of $fruit.

Any ideas how to do this in PHP?

Edit – It may not always be fruit. There is basically a set of #things and $variablesofthethings. So it will not always be fruit. But every #things will have a $variablesofthings. So, I don’t know what the thing will be but I know there is a variable for it with the same name. hope this makes sense!

  • 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-25T00:14:35+00:00Added an answer on May 25, 2026 at 12:14 am

    You could use variable variables in PHP to have your value, and then use PHP built-int string interpolation to place the value of the variable in the string.
    this way your variable names could be dynamic too.

    Variable Variables:
    in PHP you could have a variable like this:

    $fruit = 'apple';
    $car = 'toyota';
    

    But you could have a variable, whose name is detected from another variable. like this:

    $$name;
    

    This references to the variable whose name is the value of the variable $name. So for example if you receive the value of variable $name from the CLI arguments:

    $name = $argv[1];
    

    Then if the user enters ‘fruit’ in the command line, your variable $name would have the value of ‘fruit’, and then $$name would refer to the variable named $fruit with the value of ‘apple’.

    $$name; // --> 'apple'
    

    now you could use PHP interpolation (in strings enclosed by double quotes) to replace the variable, with its value:

    echo "I have a $$name"; // --> I have a apple.
    

    Here is completed example of how to do this:

    $father = "John";
    $mother = "Marta";
    $brother = "Henry";
    $relative = $$argv[1]; // or you could read the relative from any source
    echo "I love $relative";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
In Java, suppose I have a String variable S, and I want to search
i have a long string variable and i want to search in it for
I have a search text field which searches a particular column in a table,
I have a string s and I want to search for the substring of
I have a string of letters and I want to search it for a
I have the following: string html_string = http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=pharma; string html; html = new WebClient().DownloadString(html_string);
I have a folder full of files and I want to search some string
I have a search method that takes in a user-entered string, splits it at
I have an active directory search function: Function GetAdInfo(ByVal ADDN As String, ByVal ADCommonName

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.