我想从代码的某些行获取一个值,这是我当前的代码:
$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 :(得分:1)
你必须在正则表达式中使用delimeters /:
preg_match要求你做这样的事情
preg_match('/{pattern}/', $subject);
假设您想获得href链接,那么正则表达式应该是
$patternopenload = "/<a class='capitulo2' href='(.+)' rel='.+' target='.+'/";
返回 anonim.php?id = 4936681&amp; e =