문제

나는 방금 도움을받은 질문에 갇혔습니다. 새로운 문제는 조금만 있습니다.

Href의 내용을 얻기 위해이 preg_match가 있습니다. Regex를 사용하지 말라고 말하지 마십시오. 다른 파서/클래스 등을 사용하는 것을 알고 있지만 지금은 해결 해야하는 오래된 스크립트입니다. :) 재 작성을위한 시간이 없습니다!

preg_match("~<a target=\'_blank\' rel=\'nofollow\' href=\"(.*?)\">~i", $epilink, $epiurl);

반환 :

http://www.example.com/frame2.php?view=&epi=54673-r

그러나 반환해야합니다.

http://www.example.com/frame2.php?view=168204&epi=54673

이것은 HTML의 예입니다.

<a target='_blank' rel='nofollow' href="http://www.example.com/frame2.php?view=545903&epi=54683">

내가 오르플 폼을 반환 한 URL은 왜?

도움을 주셔서 감사합니다.

도움이 되었습니까?

해결책

$string="<a target='_blank' rel='nofollow' href=\"http://www.example.com/frame2.php?view=545903&epi=54683\">";
$s = explode('">',$string);
foreach($s as $k){
   if (strpos($k,"href")!==FALSE){
        echo preg_replace('/.*href="|/ms',"",$k);
        break;
   }
}

산출

$ php test.php
http://www.example.com/frame2.php?view=545903&epi=54683

다른 팁

이것은 작동해야합니다 :

$epilink = "<a target='_blank' rel='nofollow' href=\"http://www.example.com/frame2.php?view=545903&epi=54683\">";
preg_match("/<a target='_blank' rel='nofollow' href=\"(.*?)\">/i", $epilink, $epiurl);

print_r ($ epiurl);

당신은 또한 사용할 수 있습니다 preg_match_all

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top