Search code examples
phpphp4

PHP: Parse url from css property


I have a string from css (background property):

$sStr = 'url(http://www.ser.com/styles/../img/big-logo.gif) 10px 0 no-repeat';

Now I need the url of the image file like this:

'http://www.server.de/styles/../media/visuals/big-logo.gif'

Thanks for help


Solution

  • It can be done a couple different ways, but in my opinion the easiest is regex.

    if (preg_match('/url\(([^)]+)\)/i', $subject, $regs)) {
        $result = $regs[1];
    } else {
        $result = "";
    }