Forum Moderators: coopster

Message Too Old, No Replies

Newbie lost in preg replace

php preg_replace regular expression

         

numediaweb

3:57 pm on May 17, 2008 (gmt 0)

10+ Year Member



hello folks out there
sinc yesterday, i tray to get a regular expression to work but in vain .
I want a methode that checks a string and strips away some characters and echo the result;

from this;
$in = '10. Prom Night (2008) - $1.0M';

to this;
$out = 'Prom+Night+(2008)';

the number in the begining may varry from 1 to 100 but it's always limited by a dot (.)
the data at the end (- $1.0M) may varry like; (- $100.990M) but it always begin with (-)
the result as you can see, should not contain spaces, but, plus signs replacing spaces.

thank you in advance for providing a regular expression handling this .

numediaweb

5:12 pm on May 17, 2008 (gmt 0)

10+ Year Member



comon php gurus, where are you :-) littel help for old man!

dreamcatcher

6:19 pm on May 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld. :)

Please be patient. Its the weekend and it can be quiet around here. A solution will follow soon I`m sure.

dc

dublinmike

6:23 pm on May 17, 2008 (gmt 0)

10+ Year Member



Hi there,

Try this:


function stripChars($str)
{
$str = preg_replace('/^[0-9]+\. /','',$str);
$str = preg_replace('/ -+.+/','',$str);
return $str;
}

$out = stripChars('10. Prom Night (2008) - $1.0M');

// you can either urlencode the result but that will replace the () characters
// as well, if you just want to replace the spaces with the + character,
// use str_replace(' ','+',$out);

print $out;

numediaweb

7:27 pm on May 17, 2008 (gmt 0)

10+ Year Member



Thank you verry much.. you made my life easier !