DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Preg_replace Technique #1

  • submit to reddit
        // This is a useful technique for passing matched data into other
// functions to be evaluated and replaced in parsed strings.
// This example is simple. It rewrites the <img> tag emulating being
// passed thru a proxy.

$html = file_get_contents('');
print "$html<br><br>";
$attr= 'src';
print "<!-- $html -->";

function make_new_img_tag($attr, $filename, $prefix, $webroot) {
    $b64val = base64_encode($filename);
    return $prefix$attr.'="'.$webroot.'/browse/'.$b64val.'"';