3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $image = 'image/testing.jpg'; $url = 'http://testing.com'; $image_parts = parse_url($image); $url_parts = parse_url($url); // check to see if the image has a path of its own if (dirname($image_parts['path']) == '.') { $image_path = dirname($url_parts['path']) . DS . $image_parts['path']; } else { $image_path = $image_parts['path']; } if (empty($image_parts['host'])) { $image_location = sprintf('%s://%s/%s/%s', $url_parts['scheme'], $url_parts['host'], dirname($url_parts['path']), $image_path); } else { $image_location = $image; } var_dump($image_location);
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Notice: Undefined index: path in /in/75Q4Q on line 17 string(37) "http://testing.com//image/testing.jpg"
Output for 4.3.0 - 5.2.17
Notice: Undefined index: path in /in/75Q4Q on line 17 string(37) "http://testing.com//image/testing.jpg"