1

I need to parse the url in php. The url starts with // is parsing correctly in php 5.5 but not in 5.3. php 5.3 does return "host" as null and it returns domain with path in "path". I am getting the url form remote site. I am also getting the url like "//images/mdb_shoppingBag.png". For this I need to add the host name before the url. So, I can't add http://. Is there any solution?

<?php 
    $sty = '//dimg.dillards.com/is/image/DillardsZoom/03707963_zi?$c7product$';
    print_r( parse_url($sty) );
?>

And the output is

in PHP 5.5
Array ( [host] => dimg.dillards.com [path] => /is/image/DillardsZoom/03707963_zi [query] => $c7product$ )

in PHP 5.3
Array ( [path] => //dimg.dillards.com/is/image/DillardsZoom/03707963_zi [query] => $c7product$ )
hakre
  • 193,403
  • 52
  • 435
  • 836
user3350854
  • 55
  • 1
  • 1
  • 6
  • Can you just add a fake schema, make the url like http:// dimg.dillards.com...? – Andrew Feb 28 '14 at 06:07
  • Thanks. But I am getting the url form remote site. I am also getting the url like "//images/mdb_shoppingBag.png". If I'm adding http:// means, that goes wrong. – user3350854 Feb 28 '14 at 06:14
  • With "//images/mdb_shoppingBag.png", the host will be "image", is that right? – Andrew Feb 28 '14 at 06:19
  • i facing same issue [scheme] => http [host] => http [user] => user [pass] => pass [path] => //w8.a.com/file/v9wujb3v on PHP Version 5.5.6 – madman Feb 28 '14 at 19:10
  • 1
    This question appears to be off-topic because it is about an unsupported version of PHP and the obvious solution to the problem is to upgrade to a supported version that has this bug fixed. – NikiC Mar 03 '14 at 10:00
  • parse_url is not RFC conform anyway. It's a good guess function. If you need something following the standards, take a library like [Net_URL2](https://github.com/pear/Net_URL2) or similar. – hakre Mar 03 '14 at 10:15

0 Answers0