Connecting Tech Pros Worldwide Help | Site Map

REGEX help please

  #1  
Old September 29th, 2005, 12:55 PM
Defaultman
Guest
 
Posts: n/a
Hi,

I have 2 issues concerning regex:

1) change a string of:
number\number\number 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.

  #2  
Old September 29th, 2005, 02:15 PM
Zilla
Guest
 
Posts: n/a

re: REGEX help please


Defaultman wrote:[color=blue]
> 1) change a string of:
> number\number\number 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($var, 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.
  #3  
Old September 29th, 2005, 04:15 PM
Defaultman
Guest
 
Posts: n/a

re: REGEX help please


Thank you, Zilla.

It works like what I want. :)

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex help please Tim Nash (aka TMN) answers 8 August 27th, 2008 12:45 PM
Regex help please answers 1 November 17th, 2005 03:50 AM
Regex help, please - Recognize quoted strings? Dave answers 6 November 16th, 2005 01:56 PM