preg_replace() replacing all in loop

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sicapitan@gmail.com

    preg_replace() replacing all in loop

    preg_match( "|<!-- InstanceBegin(. *)(-->)(.*)<!-- InstanceEnd -->|U",
    $contents, $matches );

    $my_template = $matches[0];
    preg_match_all( "|<!-- InstanceBeginEd itable(.*)(-->)(.*)<!--
    InstanceEndEdit able -->|U", $my_template, $editables );

    $keys = array_keys( $editables[1] ); // from the editable region
    names
    foreach ($keys as $key)
    {
    $k = trim( ereg_replace( '["]', "", $key ) );

    $on_mouse_over = "onMouseOver=hi _frame('$k');";
    $on_mouse_out = "onMouseout=lo_ frame('$k');";
    $on_mouse_click =
    "onClick=url_re fresh('?option= com_oscar&task= editarea&area=" .urlencode($k). "');";
    $new_contents = "<div id=$k $on_mouse_over $on_mouse_out
    $on_mouse_click >". $editables[0][$k] ."</div>";


    $pattern = "|<!-- InstanceBeginEd itable(.*)(-->)(.*)<!--
    InstanceEndEdit able -->|U";
    $placeholder = "<!--%ed".$k."-->";
    $replaced_edita bles = preg_replace($p attern, $placeholder,
    $my_template);

    }

    I want to loop through a string and replace the first instance of the
    reg with <!--%ed0--> and the second with <!--%ed1--> etc untill the
    loop has finished. But when I look at the output, the file is filled
    with the last number - any ideas?

    thanks

  • Daniel Tryba

    #2
    Re: preg_replace() replacing all in loop

    sicapitan@gmail .com wrote:
    [snip]

    If you want to post code: make it easy to read: compact and snip the
    irrelevant stuff.
    [color=blue]
    > I want to loop through a string and replace the first instance of the
    > reg with <!--%ed0--> and the second with <!--%ed1--> etc untill the
    > loop has finished. But when I look at the output, the file is filled
    > with the last number - any ideas?[/color]

    Then your code is not complete, I don;'t see any line that outputs
    anything. All T see is 1 preg_replace overwriting the same variable
    again and again.

    Comment

    Working...