note 27440 deleted from function.preg-replace-callback by sniper

From: Date: Tue, 30 Sep 2003 12:26:26 +0000
Subject: note 27440 deleted from function.preg-replace-callback by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-57455@lists.php.net to get a copy of this message
Note Submitter: dudus ---- 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)

« previous php.notes (#57455) next »