Pulling variables from str_replace

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Brad Everman

    Pulling variables from str_replace


    Something simple, perhaps someone can shed some light.

    I have an array of paragraphs of text and am replacing some of the text
    using str_replace().

    Ex.

    function addGraphic($num Graphic){

    return("this is graphic $numGraphic");

    }

    $instruction = str_replace("#G RAPHIC[$i]",addGraphic($i ),$instruction) ;


    Basically, I look for the tag #GRAPHIC[n] in the text where n is an
    integer value and want to replace it with the text and the actual number
    inside the brackets. I am unsure how to parse this value out and then pass
    it to the function that will create the appropriate output.

    Thanks for any help.
  • Blayde

    #2
    Re: Pulling variables from str_replace


    Brad Everman wrote:
    Something simple, perhaps someone can shed some light.
    >
    I have an array of paragraphs of text and am replacing some of the text
    using str_replace().
    >
    Ex.
    >
    function addGraphic($num Graphic){
    >
    return("this is graphic $numGraphic");
    >
    }
    >
    $instruction = str_replace("#G RAPHIC[$i]",addGraphic($i ),$instruction) ;
    >
    >
    Basically, I look for the tag #GRAPHIC[n] in the text where n is an
    integer value and want to replace it with the text and the actual number
    inside the brackets. I am unsure how to parse this value out and then pass
    it to the function that will create the appropriate output.
    >
    Thanks for any help.
    Hey Brad,
    You need preg_replace_ca llback(). str_replace() won't work with more
    than one string unless you make a huge array for the search and replace
    params.
    -Blayde

    Comment

    • Brad Everman

      #3
      Re: Pulling variables from str_replace

      In a contingent reality, Blayde possibly said:
      >
      Hey Brad,
      You need preg_replace_ca llback(). str_replace() won't work with more
      than one string unless you make a huge array for the search and replace
      params.
      -Blayde
      Thanks, that worked perfectly.




      Comment

      Working...