Forum Moderators: coopster

Message Too Old, No Replies

Can't get strtolower to work inside a preg_replace

         

DrDoc

5:06 pm on Apr 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



$string = preg_replace("/(-[A-Z])/",strtolower(),$string);

I want to lowercase all letters immediately preceded by a dash. But no matter what I pass as an argument to strtolower() nothing happens...

toadhall

6:57 pm on Apr 12, 2003 (gmt 0)

10+ Year Member



Try:

$str = preg_replace("/(-[A-Z])/e","strtolower('\\0')",$string);

/e modifier makes preg_replace() treat the replacement parameter as PHP code after the appropriate references substitution is done.

\\0 or $0 refers to the text matched by the whole pattern.

[php.net ]

T

DrDoc

7:03 pm on Apr 12, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got it to work... The problem was a space after the - in the string :)