[ create a new paste ] login | about

Link: http://codepad.org/NDoya4NC    [ raw code | output | fork ]

MASKAS - PHP, pasted on Nov 19:
<?php ob_start(); ?>

    #TEST {
    	background:url(test.jpg);
    	background:url( 'test.jpg' );
    	background:url("test.jpg"  );
    	background:url(http://example.com/test.jpg);
    	background:url('https://example.com/test.jpg');
    	background:url("http://example.com/test.jpg");
    	background:url( '//example.com/test.jpg' );
    	background:url( "//example.com/test.jpg" );
    	background:url(//example.com/test.jpg);
        background:url(data:image/png;base64,iVBORw0KG);
        background:url("data:image/gif;base64,R0lGODlhCwAHAIAAACg");
        background:url("../../test.jpg");
        background:url('../test.jpg');
    }
<?php
$css = ob_get_clean();
$path = '/themes/default/css/';

$absoluteUrl = '((?:https?:)?//)';
$rawData = '(?:data\:?:)';
$relativeUrl = '\s*([\'"]?((' . $absoluteUrl . ')|(' . $rawData . ')))';
$search = '#url\((?!' . $relativeUrl . ')\s*([\'"])?#';
//$search = '#url\((?!\s*([\'"]?(((?:https?:)?//)|(?:data\:?:))))\s*([\'"])?#';
$replace = "url($6{$path}";
echo preg_replace($search, $replace, $css);


Output:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

    #TEST {
    	background:url(/themes/default/css/test.jpg);
    	background:url('/themes/default/css/test.jpg' );
    	background:url("/themes/default/css/test.jpg"  );
    	background:url(http://example.com/test.jpg);
    	background:url('https://example.com/test.jpg');
    	background:url("http://example.com/test.jpg");
    	background:url( '//example.com/test.jpg' );
    	background:url( "//example.com/test.jpg" );
    	background:url(//example.com/test.jpg);
        background:url(data:image/png;base64,iVBORw0KG);
        background:url("data:image/gif;base64,R0lGODlhCwAHAIAAACg");
        background:url("/themes/default/css/../../test.jpg");
        background:url('/themes/default/css/../test.jpg');
    }


Create a new paste based on this one


Comments: