note 27440 added to function.preg-replace-callback

From: Date: Fri, 06 Dec 2002 00:53:17 +0000
Subject: note 27440 added to function.preg-replace-callback
Groups: php.notes 
Request: Send a blank email to php-notes+get-40396@lists.php.net to get a copy of this message
Here is an sample function, I hope it could be usefull for you: The function matches the pattern [img](url)[/img], and replaces it to <IMG src=(url)> IF and only if the corresponding image isn't bigger than 200x200 pixels. function callback_check_images($matches) { $str = $matches[1].$matches[2]; $data = getimagesize($str); if (($data[0] <= 200) && ($data[1] <= 200)) return "<IMG src='$str'>"; return ""; } $text = preg_replace_callback( "/\[img\]([^\?]*)(\.gif|\.jpe?g|\.GIF|\.JPE?G)\[\/img\]/", 'callback_check_images', $text); // $matches[1] matches the first parenthensis ([^\?]*), $matches[2] the second (\.gif|\.jpe?g|\.GIF|\.JPE?G). // $matches[0] is the whole matching substring (I don't use it) -- http://www.php.net/manual/en/function.preg-replace-callback.php http://master.php.net/manage/user-notes.php?action=edit+27440 http://master.php.net/manage/user-notes.php?action=delete+27440 http://master.php.net/manage/user-notes.php?action=reject+27440

« previous php.notes (#40396) next »