Skip to content
Advertisement

PHP Resolving URL format with Base URL Relative Path into Absolute

I get some html code from other website. Using Bellow Code

JavaScript

From Here I get like this code

JavaScript

I get all the href attribute by using Regex.

JavaScript

Now all this links has no domain and paths

But I want to get all this links like bellow(I hope all links are format link this)

JavaScript

How can I transform relative path into absolute URL using PHP.

By use my main URL and the href attributs links with PHP.

(THANKS)

Advertisement

Answer

Transform Relative Path Into Absolute URL Using PHP

JavaScript

Testing …

JavaScript

Test Output …

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement