Professional Web Applications Themes

callback function in class - PHP Development

Basic problem: I need to use preg_replace_callback, and would like the callback parameter to be a function in a class (the same as that which contains the call to preg_replace_callback). "classname::function" doesn't seem to work... Anyone have any ideas? If it helps: I'm creating a class which will basically p an enhanced version of phbb2's bbcode, and output it to XHTML, PDF, etc. If someone puts [size=small] (I won't be using integers like bbcode does), I need to make sure "small" is a valid word (rejects [size=foo], [size=bar], but [size=large] is okay) -Evan...

  1. #1

    Default callback function in class

    Basic problem:

    I need to use preg_replace_callback, and would like the callback parameter to
    be a function in a class (the same as that which contains the call to
    preg_replace_callback). "classname::function" doesn't seem to work... Anyone
    have any ideas?

    If it helps:

    I'm creating a class which will basically p an enhanced version of phbb2's
    bbcode, and output it to XHTML, PDF, etc. If someone puts [size=small] (I
    won't be using integers like bbcode does), I need to make sure "small" is a
    valid word (rejects [size=foo], [size=bar], but [size=large] is okay)


    -Evan
    Evan Nemerson Guest

  2. #2

    Default Re: [PHP] callback function in class

    Evan Nemerson wrote:
    > Basic problem:
    >
    > I need to use preg_replace_callback, and would like the callback parameter to
    > be a function in a class (the same as that which contains the call to
    > preg_replace_callback). "classname::function" doesn't seem to work... Anyone
    > have any ideas?
    Besides create_function(), the very first comment on the
    preg_replace_callback() page says:

    ---
    Also, if you want to use a *static* class method for the callback
    function, you can refer to it like this:
    preg_replace_callback(pattern, array('ClassName', 'methodName'), subject)

    In PHP5, from within the class:
    preg_replace_callback(pattern, array('self', 'methodName'), subject)
    ---
    ---John Holmes...

    Amazon Wishlist: [url]www.amazon.com/o/registry/3BEXC84AB3A5E/[/url]

    PHP|Architect: A magazine for PHP Professionals [url]www.phparch.com[/url]




    John W. Holmes Guest

Similar Threads

  1. Replies: 0
    Last Post: October 26th, 05:37 PM
  2. #25988 [NEW]: ob_start (); can't register CLASS method as a callback function
    By MDonatas at centras dot lt in forum PHP Development
    Replies: 0
    Last Post: October 26th, 08:32 AM
  3. calling class function from CoreAudio callback
    By Michael Ash in forum Mac Programming
    Replies: 0
    Last Post: August 20th, 04:18 AM
  4. how to use array_map() with a class callback function?
    By Jean-Christian Imbeault in forum PHP Development
    Replies: 1
    Last Post: August 13th, 07:40 AM
  5. [PHP] how to use array_map() with a class callback function?
    By Peter James in forum PHP Development
    Replies: 0
    Last Post: August 13th, 06:40 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139