How PHP regular expressions get the video address and title in the content

Source: Internet
Author: User
For example, the article content contains the following link address:

This is MKV video test
This is the MOV video test
This is the SWF video test
This is AVI video test
This is the MP4 video test.


I want to get the following result through the regular:
Array
url = mkv_test.mkv,
title = This is MKV video test
)
Array
url = Mov_test.mov,
title = This is MOV video test
)
Array
url = swf_test.swf,
title = This is the SWF video test
)
......

Ask how to write the regular, anxious to beg for urgent


Reply to discussion (solution)

$s = <<< txt This is the MKV video test which is the MOV video test which is the SWF video test which is the AVI video test which is the MP4 video test txt;preg_match_all ('/href= ' (. +) "> (. +) $v) {    $arr [] = array (' url ' = = $v, ' title ' = [2][$k]);} Print_r ($arr);

$STR = <<< Mark this is the MKV video test which is the MOV video test which is the SWF video test which is the AVI video test which is the MP4 video test mark; $rule = ' #\ (. *?) \<\/a># ';p reg_match_all ($rule, $str, $arr), $item =array (), foreach ($arr [1] as $k + = $v) {  $item []=array (' URL ' = ' $v, ' title ' and ' = ' $arr [2][$k]);} Print_r ($item);


Array (    [0] = = Array        (            [url] + mkv_test.mkv            [title] = = This is MKV video test        )    [1] = = Array        (            [url] = = Mov_test.mov            [title] and this is MOV video test        )    [2] = = Array        (            [url] = swf _test.swf            [title] = = This is the SWF Video test        )    [3] = = Array        (            [url] = Avi_test.avi            [title] = = This is the AVI video test        )    [4] = = Array        (            [url] = = Mp4_test.mp4            [title] + = This is MP4 video test)        )

$STR = <<< Mark this is the MKV video test which is the MOV video test which is the SWF video test which is the AVI video test which is the MP4 video test mark; $rule = ' #\ (. *?) \<\/a># ';p reg_match_all ($rule, $str, $arr), $item =array (), foreach ($arr [1] as $k + = $v) {  $item []=array (' URL ' = ' $v, ' title ' and ' = ' $arr [2][$k]);} Print_r ($item);


Array (    [0] = = Array        (            [url] + mkv_test.mkv            [title] = = This is MKV video test        )    [1] = = Array        (            [url] = = Mov_test.mov            [title] and this is MOV video test        )    [2] = = Array        (            [url] = swf _test.swf            [title] = = This is the SWF Video test        )    [3] = = Array        (            [url] = Avi_test.avi            [title] = = This is the AVI video test        )    [4] = = Array        (            [url] = = Mp4_test.mp4            [title] + = This is MP4 video test)        )

Thank you for two big answer, the problem has been solved perfectly

Thank you for two big answer, the problem has been solved perfectly

  • 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.