Jump to content

ryonn

New Members
  • Posts

    3
  • Joined

  • Last visited

ryonn's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi josh, Thank you for the explanation about the modifiers. New things to learn everyday =) About the 'use', it is something new for me. I have checked the phpinfo in my server, it is 5.3.26 but it gives error: Parse error: syntax error, unexpected T_USE, expecting '{' in filename yada yada Here is my code: function makeUppercase($m) use ($test) { return strtoupper($m[1].$test); } $ret = 'the [%quick%] brown fox jumps [%over%] the lazy dog [%lorem%] ipsum dolor sit amet'; $test='foobar'; $ret = preg_replace_callback('#\[%(.+?)%\]#', 'makeUppercase', $ret); echo $ret; I guess 'use' can only be used for the 'inline' function right? I try to avoid using global since it seems not nice for me, but at this point I think there is no other option
  2. Hi Ch0cu3r, Thanks for the reply solution. It works great! For the function makeUppercase($m) { return strtoupper($m[1]); } Is there a way to make another parameter? Because I want to make it so that: // Not the actual code $test = "(somewords)"; function makeUppercase($m) { return strtoupper($m[1] . $test); } @Josh: You're right. i am not really sure about what the letters are about. I tried removing one by one, everything still seems to work fine: $ret = preg_replace_callback('#\[%(.+?)%\]#', 'makeUppercase', $ret); What do you think?
  3. Hi all, I am new to php and regex. I was told to update the following string: the [%quick%] brown fox jumps [%over%] the lazy dog [%lorem%] ipsum dolor sit amet to be the QUICK brown fox jumps OVER the lazy dog LOREM ipsum dolor sit amet Basically its just to uppercase the string withing [% %] How can I achieve this? I have done several experiments, but no avail: Such as this.. not working: $ret = "the [%quick%] brown fox"; $ret = preg_replace('#\[%(.+)%\]#iUs', strtoupper($1), $ret); echo $ret; Please help
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.