I have tried to use the following unsuccessfully:
trim()
preg_replace()
strstr()
I need to take a file location in my database similar to the following:
C:\mysite\Europe\Spain\Barcelona\Misc\Barcelona.jpg
and convert it to the following:
Thumbnails/mysite/Europe/Spain/Barcelona/Misc/Barcelona.jpg
It seems I would use trim() to trim the C:\ and then preg_replace() to convert the backslashes to forward slashes
Then add the Thumbnails string using .
Am I in the ballpark? I know it is very simple, but I just can not get it right.
Any insight would be appreciated
Trimming and Replacing Text to Create New String
Moderator: General Moderators
Hello
This is quick and dirty... curious to see other ideas..
HTH
hanji
This is quick and dirty... curious to see other ideas..
Code: Select all
<?
$val = "C:\mysite\Europe\Spain\Barcelona\Misc\Barcelona.jpg";
$val = str_replace("\\","/",$val);
$val = "Thumbnails".str_replace("C:","",$val);
echo $val;
?>hanji
- feyd
- Neighborhood Spidermoddy
- Posts: 31559
- Joined: Mon Mar 29, 2004 3:24 pm
- Location: Bothell, Washington, USA
Re: Trimming and Replacing Text to Create New String
Not especially in the area.. depending on flexibility/intelligence in the conversion, you can use substr() to remove the C:, standard string concatenation to add 'thumbnails', and str_replace() to change the '\' to '/'BZorch wrote:Am I in the ballpark?