3v4l.org

run code in 300+ PHP versions simultaneously
<?php $image = './image/testing.jpg'; $url = 'http://testing.com/randomdir'; $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);

preferences:
34.58 ms | 402 KiB | 5 Q