最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

php - get href content

matteradmin8PV0评论
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I have this code

<div data-slide-id="zoom" class="overview active" data-lazy-background="" style="background-image: url(&quot;.740.jpg&quot;);">
    <a class="MagicZoom" id="magiczoom-plus" data-options="lazyZoom: true" href=".2000.jpg">

        <figure class="mz-figure mz-hover-zoom mz-inner-zoom mz-ready" style="transform: translate3d(0px, 0px, 0px);">

           <div class="mz-lens" style="top: 0px; transform: translate(-10000px, -10000px); width: 142px; height: 220px;">
                <img src=".740.jpg" style="position: absolute; top: 0px; left: 0px; width: 532px; height: 765px;">
           </div>

           <div class="mz-loading"></div>

           <img src=".740.jpg" style="max-width: 740px; max-height: 987px;">

        </figure>

   </a>

</div>

and I want to get the content in href? what can i do? i write this code but it doesnt work.

preg_match('#<div(.*)class="overview active"><a(.*)href="(.*?)">#', $data, $name);
Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

I have this code

<div data-slide-id="zoom" class="overview active" data-lazy-background="" style="background-image: url(&quot;https://dy9ihb9itgy3g.cloudfront/products/1183/d8066/d8066____black1-r.740.jpg&quot;);">
    <a class="MagicZoom" id="magiczoom-plus" data-options="lazyZoom: true" href="https://dy9ihb9itgy3g.cloudfront/products/1183/d8066/d8066____black1-r.2000.jpg">

        <figure class="mz-figure mz-hover-zoom mz-inner-zoom mz-ready" style="transform: translate3d(0px, 0px, 0px);">

           <div class="mz-lens" style="top: 0px; transform: translate(-10000px, -10000px); width: 142px; height: 220px;">
                <img src="https://dy9ihb9itgy3g.cloudfront/products/1183/d8066/d8066____black1-r.740.jpg" style="position: absolute; top: 0px; left: 0px; width: 532px; height: 765px;">
           </div>

           <div class="mz-loading"></div>

           <img src="https://dy9ihb9itgy3g.cloudfront/products/1183/d8066/d8066____black1-r.740.jpg" style="max-width: 740px; max-height: 987px;">

        </figure>

   </a>

</div>

and I want to get the content in href? what can i do? i write this code but it doesnt work.

preg_match('#<div(.*)class="overview active"><a(.*)href="(.*?)">#', $data, $name);
Share Improve this question edited Mar 3, 2019 at 20:21 Qaisar Feroz 2,1471 gold badge9 silver badges20 bronze badges asked Mar 3, 2019 at 15:20 hamed mohamad nejadhamed mohamad nejad 31 bronze badge
Add a comment  | 

1 Answer 1

Reset to default 3

I find the DOMDocument() class handles this elegantly. This snippet of code should help you (put the entire html tag including the div wrapper in the $tag variable):

$d = new DOMDocument();
$d->loadHTML($tag);
$a = $d->getElementByTagName('a');
$href = $a->item(0)->getAttribute('href');

The $hrefvariable will have the attribute value of href.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far