Page 1 of 1

replace problem

Posted: Sat Jan 01, 2011 8:37 pm
by bernte
hello and a happy new year :D

i have a little problem and my english and php is not the best but i try to explain my question :D
i get the following code from my database:

Code: Select all

$path = picfolder/picname/picname-1.jpg
i only save the path for the HQ-Picture into the database. in my imagefolder are also thumb_picname-1.jpg and crop_picname-1.jpg

i need a variable that replace the

Code: Select all

$path = picfolder/picname/picname-1.jpg
into

Code: Select all

$thumbpath = picfolder/picname/thumb_picname-1.jpg
i want to realize it at the second slash..

is it possible to search for the 2nd slash and replace it with /thumb-

from
picfolder/picname/thumb_picname-1.jpg
to
picfolder/picname/thumb_picname-1.jpg

i thank you for your help!

best regards

Re: replace problem

Posted: Sat Jan 01, 2011 9:00 pm
by Neilos
I would use the explode() function, something like;

Code: Select all

$path = "picfolder/picname/picname-1.jpg";
$pieces = explode("/", $path);

$thumbpath = $pieces[0] . "/" . $pieces[1] . "/thumb_" . $pieces[2];
I hope this is what you are looking for :)

Re: replace problem

Posted: Sat Jan 01, 2011 9:11 pm
by bernte
AWESOME!!!!!!!! THANK YOU :D