REGEX help please

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Defaultman

    REGEX help please

    Hi,

    I have 2 issues concerning regex:

    1) change a string of:
    number\number\n umber to number/number/number

    for example:
    2\0 to 2/0
    3\1\2 to 3/1/2


    2) change a string of:
    numbers to digit/digit/digit

    for example:
    321 to 3/2/1
    18 to 1/8

    Please help me with the PHP code, I have tried many hours and I
    couldn't get it to work, thanks.

  • Zilla

    #2
    Re: REGEX help please

    Defaultman wrote:[color=blue]
    > 1) change a string of:
    > number\number\n umber to number/number/number[/color]

    You don't have to use regexp to do this. Try this:

    $var = str_replace('\\ ', '/', $var);

    assuming $var contains the string you want to change.
    [color=blue]
    > 2) change a string of:
    > numbers to digit/digit/digit[/color]

    This you can du with chunk_split():

    $var = chunk_split($va r, 1, '/');

    This puts a '/' between every character in $var AND in the end. So if
    you don't want the '/' in the end you can remove it with substr():

    $var = substr($var, 0, -1);

    Hope this is useful.

    Zilla.

    Comment

    • Defaultman

      #3
      Re: REGEX help please

      Thank you, Zilla.

      It works like what I want. :)

      Comment

      Working...