November 9, 2012

List connected files as array when we call a file with php?

Question by AnzaVR

What I am trying to achieve, when I open a website, it starts a network activity by loading images, swf files, css file etc. Is there any way in php to get a list of those resources as array?

Answer by Starx

You can use regular expression to parse the links once you have all HTML markups.

Here is an example to get the CSS request:

$regexp = "<links[^>]*href=("??)([^" >]*?)\1[^>]*/>"; 
preg_match_all("/$regexp/siU", $input, $matches);
var_dump($matches);

In the same way get scripts resources, image request, and iframe request.

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!