Professional Web Applications Themes

Fw: [PHP] preg_replace - understanding - PHP Development

----- Original Message ----- From: "Micah Montoy" <montmicaisu.edu> To: <php-generallists.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 ...

  1. #1

    Default Fw: [PHP] preg_replace - understanding


    ----- Original Message -----
    From: "Micah Montoy" <montmicaisu.edu>
    To: <php-generallists.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


    Kevin Stone Guest

  2. #2

    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" <kevinhelpelf.com> wrote in message
    news:002801c345a1$e5147440$6500a8c0kevin...
    >
    > ----- Original Message -----
    > From: "Micah Montoy" <montmicaisu.edu>
    > To: <php-generallists.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
    >
    >

    Micah Montoy Guest

  3. #3

    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
    "\\\\"


    Jennifer Goodie Guest

  4. #4

    Default Re: [PHP] preg_replace - understanding

    Never mind. Its working.

    thanks

    ----- Original Message -----
    From: "Jennifer Goodie" <goodieapollointeractive.com>
    To: "Micah Montoy" <montmicaisu.edu>; <php-generallists.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
    > "\\\\"
    >
    >
    >

    Micah Montoya Guest

Similar Threads

  1. preg_replace help
    By JDJones in forum PHP Development
    Replies: 3
    Last Post: September 25th, 08:54 PM
  2. preg_replace help please
    By Justin French in forum PHP Development
    Replies: 1
    Last Post: September 25th, 01:23 AM
  3. I need help with preg_replace
    By M.I. in forum PHP Development
    Replies: 1
    Last Post: July 15th, 02:29 PM
  4. [PHP] preg_replace - understanding
    By Mike Ford in forum PHP Development
    Replies: 0
    Last Post: July 9th, 10:06 AM
  5. preg_replace - understanding
    By Micah Montoy in forum PHP Development
    Replies: 0
    Last Post: July 8th, 10:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139