Php regular expression how to get the video address and title in the content-php Tutorial

Source: Internet
Author: User
How to obtain the video address and title in the php regular expression? for example, the article content contains the following link address:

This is an mkv video test.
This is a mov video test.
This is a swf video test
This is an avi video test.
This is an mp4 video test.


I want to obtain the following result through regular expression:
Array (
Url => mkv_test.mkv,
Title => This is an mkv video test.
)
Array (
Url => mov_test.mov,
Title => This is a mov video test.
)
Array (
Url => swf_test.swf,
Title => This is a swf video test.
)
......

How can I write regular expressions?


Reply to discussion (solution)

$ S = <TXT this is mkv video test this is mov video test this is swf video test this is avi video test this is mp4 video test TXT; preg_match_all ('/href = "(. +) "> (. +)$ V) {$ arr [] = array ('URL' => $ v, 'title' => $ m [2] [$ k]);} print_r ($ arr );

$ Str = <mark: this is an mkv video test. this is a mov video test. this is a swf video test. this is an avi video test. this is an mp4 video test mark. $ rule = '#\(.*?) \ <\/A> # '; preg_match_all ($ rule, $ str, $ arr); $ item = array (); foreach ($ arr [1] as $ k => $ v) {$ item [] = array ('URL' => $ v, 'title' => $ arr [2] [$ k]);} print_r ($ item );


Array ([0] => Array ([url] => mkv_test.mkv [title] => This is an mkv video test) [1] => Array ([url] => mov_test.mov [title] => This is a mov video test) [2] => Array ([url] => swf_test.swf [title] => This is a swf video test) [3] => Array ([url] => avi_test.avi [title] => This is an avi video test) [4] => Array ([url] => mp4_test.mp4 [title] => This is an mp4 video test ))

$ Str = <mark: this is an mkv video test. this is a mov video test. this is a swf video test. this is an avi video test. this is an mp4 video test mark. $ rule = '#\(.*?) \ <\/A> # '; preg_match_all ($ rule, $ str, $ arr); $ item = array (); foreach ($ arr [1] as $ k => $ v) {$ item [] = array ('URL' => $ v, 'title' => $ arr [2] [$ k]);} print_r ($ item );


Array ([0] => Array ([url] => mkv_test.mkv [title] => This is an mkv video test) [1] => Array ([url] => mov_test.mov [title] => This is a mov video test) [2] => Array ([url] => swf_test.swf [title] => This is a swf video test) [3] => Array ([url] => avi_test.avi [title] => This is an avi video test) [4] => Array ([url] => mp4_test.mp4 [title] => This is an mp4 video test ))

Thank you for your answers.

Thank you for your answers.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.