Re: Reg Expression Search

From: Date: Tue, 17 Oct 2000 07:56:28 +0000
Subject: Re: Reg Expression Search
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-20571@lists.php.net to get a copy of this message
Scott Mebberson writes: > Hi Guys, > > I have real problems with reg exps. I hate them. > > I need to do a search on string that will look like this "C:\temp\bg.gif" > and I want to take from the end of string up until the first backslash. The > var $realVal contains the string. So I can either take it from --\[*].gif-- > or --\[*].jpg-- > > thanks for all help > > scott. Did you mean the first backslash as in the first backslash from the left, or from the right? :) If from the right, then it looks like you're trying to just get the filename, in which case basename() should help: http://www.php.net/manual/function.basename.php If from the left, then I think the easiest way would probably be with something like this: substr($path, strpos($path, '\\') + 1) . "\n"; Just on a side note, be careful when using strings with backslashes in them: if you use double-quotes with them, weird things can happen if PHP interprets the backslashes to mean escape sequences. For example, if you do 'echo "C:\temp\bg.gif";', you get: C: emp\bg.gif as ouput, since PHP thinks the \t means 'tab'. Cheers, Torben -- +----------------------------------------------------------------+ |Torben Wilson <torben@php.net> Netmill iTech| |http://www.coastnet.com/~torben http://www.netmill.fi| |Ph: 1 250 383-9735 torben@netmill.fi| +----------------------------------------------------------------+

« previous php.general (#20571) next »