note 90849 modified in function.preg-replace-callback by danbrown

From: Date: Tue, 12 May 2009 20:19:54 +0000
Subject: note 90849 modified in function.preg-replace-callback by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-154526@lists.php.net to get a copy of this message
If you're planning to use preg_replace_callback inside a class, you need to use the array() function: <?php class MyClass { function preg_callback_url($matches) { //var_dump($matches); $url = $matches[1].$matches[2]; $text = ''; $pos = strpos($url,' '); if ($pos!==FALSE) { $text = trim(substr($url,$pos+1)); $url = substr($url,0,$pos); } return '<a href="'.$url.'" rel="nofollow">'.(($text!='') ? $text : $url).'</a>'; } function ParseText($text) { return preg_replace_callback('/\[(http|https|ftp)(.*?)\]/iS',array( &$this, 'preg_callback_url'), $text); } } ?> --was-- If you're planning to use preg_replace_callback inside a class, you need to use the array() function: class MyClass { function preg_callback_url($matches) { //var_dump($matches); $url = $matches[1].$matches[2]; $text = ''; $pos = strpos($url,' '); if ($pos!==FALSE) { $text = trim(substr($url,$pos+1)); $url = substr($url,0,$pos); } return '<a href="'.$url.'" rel="nofollow">'.(($text!='') ? $text : $url).'</a>'; } function ParseText($text) { return preg_replace_callback('/\[(http|https|ftp)(.*?)\]/iS',array( &$this, 'preg_callback_url'), $text); } } http://php.net/manual/en/function.preg-replace-callback.php

« previous php.notes (#154526) next »