php
  • preg-match
  • 2017-11-11 307 views -2 likes 
    -2

    什么,我想摆脱的一些代码行的值,这是我当前的代码:不掌握的preg_match

    $body = "<td class='tam12'><img src='/assets/img/banderas/es.png' width='30' height='20' /></td><td class='tam12'>2017-05-22</td><td class='tam12'><img src='/assets/img/servidores/streamplay.jpg' width='80' height='25' style='border-radius:4px;' /></td><td><a class='capitulo2' href='anonim.php?id=4936681&e=' rel='nofollow' target='_blank' alt=''>Ver online</a>"; 
    $patternopenload = "#<img src='/assets/img/banderas/es.png' width='[^']*' height='[^']*' /></td><td class='tam12'>[^']*</td><td class='tam12'><img src='/assets/img/servidores/streamplay.jpg' width='[^']*' height='[^']*' style='[^']* /></td><td><a class='[^']*' href='(.*?)' rel='nofollow' target='_blank' alt=''>Ver online</a></td>"; 
    preg_match($patternopenload, $body, $primero); 
    echo $primero[1]; 
    

    ,但我没有得到任何东西。我不明白为什么我已经订正,至少五十次,如果有人可以帮助我,我会非常感激

    +0

    首先,不要用正则表达式解析HTML。你错过了你的正则表达式的结束分隔符(即'#')。 '...版本在线#“;' – Toto

    +0

    @Toto是的,我注意到了这一点发出的帖子后,我固定它,但它仍然无法正常工作 –

    回答

    1

    你必须使用delimeters /在正则表达式模式:

    的preg_match需要你做像这样

    preg_match('/{pattern}/', $subject); 
    

    假设你想要得到的href链接,这样的正则表达式应该是

    $patternopenload = "/<a class='capitulo2' href='(.+)' rel='.+' target='.+'/"; 
    

    返回anonim.p hp?id = 4936681 & e =

    +0

    是的,它的工作,但我必须在模式中包含两个''因为我需要他们的未来preg_match_all从只有那些imgs –

    +0

    '​​'得到href,如果我添加它它不再工作 –

    +0

    所以你想获得链接和图像的网址? –

    相关问题