Re: Reg Expression Search
| From: | Scott Mebberson | Date: | Tue, 17 Oct 2000 08:23:20 +0000 |
| Subject: | Re: Reg Expression Search | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-20575@lists.php.net to get a copy of this message | ||
Sorry Lars, the last message I wrote to you. figured it out. it was easy >>
$done = str_replace("\\", "/", $realVal);
"Lars Torben Wilson" <torben@pinc.com> wrote in message
news:14828.1580.959795.972075@shanna.outlander.ca...
> 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|
> +----------------------------------------------------------------+
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>