deathdeyfer2002 Posted November 14, 2009 Share Posted November 14, 2009 All- I have a PHP string that consists of the following. $Directory = "DIR/*FILENAME/FILEA/FILEB" Now I am currently using $Directory = strrchr($Directory, '*'); To shorten it to $Directory = "*FILENAME/FILEA/FILEB" That part is working like a champ. Where I am running into trouble is I want to make the string look like the following. $Directory = "*FILENAME Now I thought about going X amount of characters over from the * but what happens then 'FILENAME' changes in size. also tried using the strrchr function but that seems to work from left to right... I need something that works from right to left. Any Ideas???? Link to comment https://forums.phpfreaks.com/topic/181456-find-an-occurance-in-a-php-string/ Share on other sites More sharing options...
trq Posted November 14, 2009 Share Posted November 14, 2009 $Directory = "*FILENAME/FILEA/FILEB"; $Directory = substr($Directory, 0, strpos('/', $Directory)); Link to comment https://forums.phpfreaks.com/topic/181456-find-an-occurance-in-a-php-string/#findComment-957201 Share on other sites More sharing options...
deathdeyfer2002 Posted November 14, 2009 Author Share Posted November 14, 2009 Thanks for taking a look. I tried that exact code and it doesen't print anything to the screen. If I break it appart... $Directory = "*FILENAME/FILEA/FILEB"; $Directory = substr($Directory, 0); echo $Directory = strpos('/', $Directory); Still Doesn't Display anything. If I take the strpos part out, then it semi works but doesent do as needed. Link to comment https://forums.phpfreaks.com/topic/181456-find-an-occurance-in-a-php-string/#findComment-957230 Share on other sites More sharing options...
trq Posted November 14, 2009 Share Posted November 14, 2009 Sorry, I had the arguments to subpos around the wrong way. $Directory = "*FILENAME/FILEA/FILEB"; $Directory = substr($Directory, 0, strpos($Directory,'/')); echo $Directory; Link to comment https://forums.phpfreaks.com/topic/181456-find-an-occurance-in-a-php-string/#findComment-957236 Share on other sites More sharing options...
deathdeyfer2002 Posted November 14, 2009 Author Share Posted November 14, 2009 Works like a champ.. THANKS!!!! Link to comment https://forums.phpfreaks.com/topic/181456-find-an-occurance-in-a-php-string/#findComment-957243 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.