Page 1 of 1

hello help with string find & replace

Posted: Sun Oct 23, 2011 2:22 am
by kobie
i want to search for a string that looks like:

Zpx Zpx;

while Z is N=(0,.......,100)

and replace the string to:

Zpx 0px 0px Zpx;

Re: hello help with string find & replace

Posted: Sun Oct 23, 2011 4:04 am
by genix2011
Hello,

you can use preg_replace to achieve this.

Code: Select all

<?php
$string = "2px 3px;";
$pattern = "/(\d)px (\d)px\;/i";
$replace = "$1px 0px 0px $2px;";

$result = preg_replace($pattern, $replace, $string);

echo $result;
Greets.