sábado, 19 de marzo de 2016

Using indexed arrays with preg_replace()

<?php

$string = 'The quick brown fox jumped over the lazy dog.';
$patterns = array();


$patterns[0] = '/quick/';
$patterns[1] = '/brown/';
$patterns[2] = '/fox/';


$replacements = array();
$replacements[2] = 'bear';
$replacements[1] = 'black';
$replacements[0] = 'slow';



echo preg_replace($patterns, $replacements, $string);


The bear black slow jumped over the lazy dog.

No hay comentarios:

Publicar un comentario