In the past few days, you need to write a program to extract the FLASH Address of a video website address, such as an address of Youku.
In the past few days, you need to write a program to extract the FLASH Address of a video website address, such as an address of Youku.
Then I implemented this function using PHP. I think it is a pleasure to use PHP to do this job! With its powerful HTML page processing functions and regular expressions, you can use this function with just a few lines of code.
Paste the key code:
The Code is as follows:
// Obtain the flash Address on the Youku page
Function get_flash_url ($ url)
{
$ Lines = file ($ url );
Foreach ($ lines as $ linenum => $ line ){
Preg_match_all ('| | ', $ Line, $ result );
$ Swfurl = $ result [1] [0];
If (! Empty ($ swfurl ))
Return $ swfurl;
}
}
?>
$ Url = $ _ SERVER ["QUERY_STRING"];
$ Flashurl = get_flash_url ($ url );
Echo ($ flashurl );
?>
For example, if we store this file as test. php, we only need to run test. php? The url of youku video can parse the FLASH Address.
The idea is simple. First, let's look at the key FLASH Address section in the HTML code of Youku's video webpage. Find a webpage. For example, we can see this section:
Flash Address:
Then, use the regular expression to match the address segment.