Jump to content

Find an Occurance in a PHP String


deathdeyfer2002

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.