Fw: [PHP] preg_replace - understanding

This is a discussion on Fw: [PHP] preg_replace - understanding within the PHP General forums, part of the PHP Programming Forums category; ----- Original Message ----- From: "Micah Montoy" <montmica@isu.edu> To: <php-general@lists.php.net> ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-08-2003
Kevin Stone
 
Posts: n/a
Default Fw: [PHP] preg_replace - understanding


----- Original Message -----
From: "Micah Montoy" <montmica@isu.edu>
To: <php-general@lists.php.net>
Sent: Tuesday, July 08, 2003 4:01 PM
Subject: [php] preg_replace - understanding


> I'm trying to understand how the code works within the preg_replace

function
> but the manual is just obscure as the examples are. Anyway, I am looking

to
> use it to replace "\\" in a string with "/" and I can not figure how how.
> At first, I thought I could just do:
>
> $filevalue = preg_replace("'\\', /", $filevalue);
>
> but it doesn't do anything. If someone could relate what it is and what

the
> parts mean between the (), I would appreciate it.
>
> thanks


You're not using the function correctly. You've got the search string and
replace string tied up into one input there. They need to be separate.

$filevalue = preg_replace('\\', '/', $filevalue);
http://www.php.net/manual/en/function.preg-replace.php

However you should consider using the str_replace() function in your case
since you aren't doing any pattern matching and it's a lot faster than
preg_replace().

$filevalue = str_replace('\\'. '/', $filevalue);
http://www.php.net/manual/en/function.str-replace.php

--
Kevin


Reply With Quote
  #2 (permalink)  
Old 07-08-2003
Micah Montoy
 
Posts: n/a
Default Re: [PHP] preg_replace - understanding

I took a look at the str_replace function and it will work but I am getting
a weird thing happening now. When I do:

$filevalue = str_replace("\\", "/", $filevalue);

it is reversing the "\\" to "//" but not replacing them with just a single
"/".

What may be causing this?

thanks


"Kevin Stone" <kevin@helpelf.com> wrote in message
news:002801c345a1$e5147440$6500a8c0@kevin...
>
> ----- Original Message -----
> From: "Micah Montoy" <montmica@isu.edu>
> To: <php-general@lists.php.net>
> Sent: Tuesday, July 08, 2003 4:01 PM
> Subject: [php] preg_replace - understanding
>
>
> > I'm trying to understand how the code works within the preg_replace

> function
> > but the manual is just obscure as the examples are. Anyway, I am

looking
> to
> > use it to replace "\\" in a string with "/" and I can not figure how

how.
> > At first, I thought I could just do:
> >
> > $filevalue = preg_replace("'\\', /", $filevalue);
> >
> > but it doesn't do anything. If someone could relate what it is and what

> the
> > parts mean between the (), I would appreciate it.
> >
> > thanks

>
> You're not using the function correctly. You've got the search string and
> replace string tied up into one input there. They need to be separate.
>
> $filevalue = preg_replace('\\', '/', $filevalue);
> http://www.php.net/manual/en/function.preg-replace.php
>
> However you should consider using the str_replace() function in your case
> since you aren't doing any pattern matching and it's a lot faster than
> preg_replace().
>
> $filevalue = str_replace('\\'. '/', $filevalue);
> http://www.php.net/manual/en/function.str-replace.php
>
> --
> Kevin
>
>



Reply With Quote
  #3 (permalink)  
Old 07-09-2003
Jennifer Goodie
 
Posts: n/a
Default RE: [PHP] preg_replace - understanding

> $filevalue = str_replace("\\", "/", $filevalue);
>
> it is reversing the "\\" to "//" but not replacing them with just a single
> "/".


I think you need to escape your \ so each \ is \\ so your string should be
"\\\\"


Reply With Quote
  #4 (permalink)  
Old 07-09-2003
Micah Montoya
 
Posts: n/a
Default Re: [PHP] preg_replace - understanding

Never mind. Its working.

thanks

----- Original Message -----
From: "Jennifer Goodie" <goodie@apollointeractive.com>
To: "Micah Montoy" <montmica@isu.edu>; <php-general@lists.php.net>
Sent: Tuesday, July 08, 2003 5:43 PM
Subject: RE: [php] preg_replace - understanding


> > $filevalue = str_replace("\\", "/", $filevalue);
> >
> > it is reversing the "\\" to "//" but not replacing them with just a

single
> > "/".

>
> I think you need to escape your \ so each \ is \\ so your string should be
> "\\\\"
>
>
>



Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:38 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0