Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by babyfighter » Mon Aug 05, 2002 6:45 am
For an example, assume this is the string I am dealing with:
N:\NML\Perseus\Photographs\procedure pictures\02-08-02\07 Hardware attaching control panel.JPG
I need to grab the portion of the string that reads "07 Hardware attaching control panel" and store it as a variable. So basically I need to get rid of the file location and the file extension. Is there a quick way to manipulate this string to pull out only the info I need?
Thanks.
-
babyfighter
- New php-forum User

-
- Posts: 4
- Joined: Mon Aug 05, 2002 6:24 am
by Jay » Mon Aug 05, 2002 7:32 am
- Code: Select all
<?
$string = 'N:\NML\Perseus\Photographs\procedure pictures\02-08-02\07 Hardware attaching control panel.JPG';
$values = explode("\\",$string);
list($filename) = explode(".",$values[sizeof($values)-1]);
print $filename;
?>
Note that the string being enclosed in single quotes is not accidental or coincedental. I enclosed it in single quotes otherwise it will parse the '\' as a special character and the script won't work. The rest should be fairly self explanatory.
-
Jay
-
by babyfighter » Mon Aug 05, 2002 7:47 am
Thanks, Jay. It works great. I guess it's all about using that explode() function.
-
babyfighter
- New php-forum User

-
- Posts: 4
- Joined: Mon Aug 05, 2002 6:24 am
Return to PHP coding => General
Who is online
Users browsing this forum: pela222 and 1 guest