PHP: Parse url from css property

526 views Asked by At

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

2

There are 2 answers

1
simshaun On BEST ANSWER

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 = "";
}
0
AudioBubble On
preg_match("/\((.*)\)/",  $sStr,  $matches);
print_r($matches);