PDA

View Full Version : preg_replace question


leadZERO
Wed 24th Jan '01, 7:58pm
I'm trying to replace strings like "00.jpg" with "00thumb.gif"

Why is the statement:
preg_replace( "/(\d+)\.\w{3,4}$/", "\\1thumb\.gif", $thumbimage );

not working?

Zef Hemel
Sun 28th Jan '01, 2:49pm
Don't know the difference between ereg_replace and preg_replace, but I think you can leave the slashes alone, so
preg_replace( "^(\d+)\.\w{3,4}$", "\\1thumb\.gif", $thumbimage );

Might work

Rickard
Sun 28th Jan '01, 7:36pm
Zef, I didn't expect to see you hanging around here and helping out. How are things going with Yabb 2? Will it be PHP-based?

JohnM
Sun 28th Jan '01, 10:00pm
$newfilename = preg_replace( "/(\\d+)\\.\\w{3,4}\$/", "\\1thumb\\.gif", $thumbimage );

Zef Hemel
Mon 29th Jan '01, 10:25am
No, YaBB 2 will be perl based. But I like php more actually, I'm writing a new product using it.

Rickard
Mon 29th Jan '01, 12:48pm
Yeah, I know what you mean. Perl is very powerful and versatile, but I never really could get used to the syntax.

JohnM
Mon 29th Jan '01, 1:03pm
I know a fair bit of perl...

Zef Hemel
Mon 29th Jan '01, 1:40pm
Oh, well I know far more perl than php. But php has some nice features (like good mysql support), perl doesn't have (by default).