- preg_replace_callback: documentation ( source)
<?php
$text = "Hello, http://jsfiddle.net/uyuouyvz/ this is a test for jsfiddle.net";
$preg = "%(http://(www.)?[jsfiddle].net/\w+?(/\d+)?(/.*)?)%im";
$text = preg_replace_callback($preg, function($match) {
return "<iframe src=\"{$match[0]}\"></iframe>";
});
echo $text;