Limit characters in preg_replace
Posted: Sun Nov 12, 2006 8:59 am
Hi,
I'm using a regular expression to search and replace template comments in html files, below is the snippet of code responsible :
The code above replaces all wiith just name. Soo the result would be .
What I want to do is use the second match parameter (\d+) to limit the number of charaters name is rpelaced with.
For instance :
should translate to
is this possible?
Any help would be appreciated.
Musaffar
I'm using a regular expression to search and replace template comments in html files, below is the snippet of code responsible :
Code: Select all
$string = preg_replace("#<!--%(.*?:)(\d+)%-->#", "$1", $string);Code: Select all
<!--%name:8%-->Code: Select all
<!--%name%-->What I want to do is use the second match parameter (\d+) to limit the number of charaters name is rpelaced with.
For instance :
Code: Select all
<!--%Description:5%-->Code: Select all
<!--%Descr%-->Any help would be appreciated.
Musaffar