Jump to content

Capturing back references from preg_replace as variables


jamessw

Recommended Posts

Here's an example-

 

$string = 'First worked | FAIL   |           ';
$pattern = '%(.+) \| (.+) \| .+%i';
$replacement = '{$first = $1}{$second = $2}';
echo preg_replace($pattern, $replacement, $string);

echo $first;

 

How would I use an array in the replacement pattern?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.