Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

string manipulation

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

string manipulation

Postby 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
New php-forum User
 
Posts: 4
Joined: Mon Aug 05, 2002 6:24 am

Postby 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
 

Postby 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
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: Google [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron