replace problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bernte
Forum Newbie
Posts: 2
Joined: Sat Jan 01, 2011 8:15 pm

replace problem

Post 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
Neilos
Forum Contributor
Posts: 179
Joined: Fri Nov 19, 2010 2:07 am

Re: replace problem

Post 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 :)
bernte
Forum Newbie
Posts: 2
Joined: Sat Jan 01, 2011 8:15 pm

Re: replace problem

Post by bernte »

AWESOME!!!!!!!! THANK YOU :D
Post Reply