Forum Moderators: coopster

Message Too Old, No Replies

preg_replace question (w. example)

i have a question regarding preg_replace

         

asantos

2:28 am on Mar 14, 2006 (gmt 0)

10+ Year Member



i have this variables:
$url = '/products/computers/_es/';
$pat = '/(_[a-zA-Z]{2})/';
$rep = '';

i need to get rid of the '_xx/' part. with that $pat pattern, a preg_replace($pat,$rep,$url) returns '/products/computers//'

and worst, if the $url changes to '/products/_es/computers/' it returns '/products//computers/' while it should'nt to ANYTHING at all.

the preg_replace must only work when the _XX/ is at the end of the $url.

i need help in that, thanks!
andres

DrDoc

4:11 am on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are not including the slashes in your pattern.
The dollar sign marks end of string.

$pat = '/\/_[a-zA-Z]{2})\/?$/';
$rep = '/'