$html = preg_replace('/(&?)([^&a-zA-Z0-9\-_\.]page=)[^&]*(&?[^>]*>Go back.*)/i', '$1page=' . $_REQUEST['origPage'] . '$3', $html);

This pattern replacement obliterates the entire value of $html each time I use it.

Consider this:

$html = '
<a href="index.php?section=image&action=edit&sort=&willKeepPageSession=1&page=2">Go back to your previous listing</a>
';

I need to take that predefined value of $html and manipulate the contents so that

&page=2

Becomes

&page=<?= $_REQUEST['origPage'] ?>

Using preg_replace(), however, obliterates all of $html so that it becomes null.

Is there something else I can use then besides preg_replace() to do this precise replacement within the $html HTML string? I obviously can't use preg_replace()!

Thanx
Phil

    Now it got worse!!! I had to literaly reboot my server box when using this line:

    $html = preg_replace('/(&?)(?!.page=)[^&]*(&?[^>]*>Go back.*)/i', '$1page=' . $_REQUEST['origPage'] . '$3', $html);
    

    PHP locks up, Firefox crashes, Apache goes down and all other Linux resources on my box are locked down cold!

    Phil

      if i understand your regex, you are trying to replace the value of the "page" GET var in all of your links to $REQUEST['origPage'], right? assuming that page is always the last GET var in all of your href's then this should work:

      $html = '<a href="index.php?section=image&action=edit&sort=&willKeepPageSession=1&page=2">Go back to your previous listing</a>';
      $html = preg_replace('/\&page=([^\[]*)\"/', '&page=' . $_REQUEST['origPage'] . '"', $html);
      echo $html;
      

        Unfortunately you can't assume that. The query strings in $html are dynamically generated, thus "page=" can be at the beginning, at the end, in the middle, or not at all.

        After a few good hours of hair-pulling, this seems to work, but it's very unstable:

        		$html = preg_replace('/(&?[^a-zA-Z0-9\-_\.])page=[^&">]*(&?[^>]*>Go back.*)/i', '$1page=' . $_REQUEST['origPage'] . '$2', $html);
        

        Phil

          Write a Reply...