How to get href value from string











up vote
0
down vote

favorite












I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.



<table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
<tbody>
<tr>
<th align="left" valign="middle" scope="col">Code</th>
<th align="left" valign="middle" scope="col">Subject</th>
<th align="left" valign="middle" scope="col">Status</th>
<th align="center" valign="middle" scope="col">Score</th>
<th align="center" valign="middle" scope="col">Result Date</th>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PQ
</td>
<td align="left" valign="middle">
<span class="">
1561|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved ">
<img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
[Project Quality] </a>
</span>
<span class="selected">
</span>
</td>
<td align="left" valign="middle">
<span class="enable">
Competent
</span>
<center style="display: none">
<span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
</center>
</td>
<td align="center" valign="middle">
75.00
</td>
<td align="center" valign="middle">
11/11/2018
</td>
</tr>
<tr class="detail1">
<td align="left" valign="middle">
DipPM15PC
</td>
<td align="left" valign="middle">
<span class="">
1559|
<a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559" title="NAN ">
<img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
[Project Costs] </a>
</span>
<span class="selected">
[progress]
</span>
</td>
<td align="left" valign="middle">
<span class="disable">
</span>
<center style="display: none">
</center>
</td>
<td align="center" valign="middle">
</td>
<td align="center" valign="middle">
</td>
</tr>
</tbody>











share|improve this question




























    up vote
    0
    down vote

    favorite












    I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.



    <table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
    <tbody>
    <tr>
    <th align="left" valign="middle" scope="col">Code</th>
    <th align="left" valign="middle" scope="col">Subject</th>
    <th align="left" valign="middle" scope="col">Status</th>
    <th align="center" valign="middle" scope="col">Score</th>
    <th align="center" valign="middle" scope="col">Result Date</th>
    </tr>
    <tr class="detail1">
    <td align="left" valign="middle">
    DipPM15PQ
    </td>
    <td align="left" valign="middle">
    <span class="">
    1561|
    <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved ">
    <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
    [Project Quality] </a>
    </span>
    <span class="selected">
    </span>
    </td>
    <td align="left" valign="middle">
    <span class="enable">
    Competent
    </span>
    <center style="display: none">
    <span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
    </center>
    </td>
    <td align="center" valign="middle">
    75.00
    </td>
    <td align="center" valign="middle">
    11/11/2018
    </td>
    </tr>
    <tr class="detail1">
    <td align="left" valign="middle">
    DipPM15PC
    </td>
    <td align="left" valign="middle">
    <span class="">
    1559|
    <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559" title="NAN ">
    <img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
    [Project Costs] </a>
    </span>
    <span class="selected">
    [progress]
    </span>
    </td>
    <td align="left" valign="middle">
    <span class="disable">
    </span>
    <center style="display: none">
    </center>
    </td>
    <td align="center" valign="middle">
    </td>
    <td align="center" valign="middle">
    </td>
    </tr>
    </tbody>











    share|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.



      <table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
      <tbody>
      <tr>
      <th align="left" valign="middle" scope="col">Code</th>
      <th align="left" valign="middle" scope="col">Subject</th>
      <th align="left" valign="middle" scope="col">Status</th>
      <th align="center" valign="middle" scope="col">Score</th>
      <th align="center" valign="middle" scope="col">Result Date</th>
      </tr>
      <tr class="detail1">
      <td align="left" valign="middle">
      DipPM15PQ
      </td>
      <td align="left" valign="middle">
      <span class="">
      1561|
      <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved ">
      <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
      [Project Quality] </a>
      </span>
      <span class="selected">
      </span>
      </td>
      <td align="left" valign="middle">
      <span class="enable">
      Competent
      </span>
      <center style="display: none">
      <span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
      </center>
      </td>
      <td align="center" valign="middle">
      75.00
      </td>
      <td align="center" valign="middle">
      11/11/2018
      </td>
      </tr>
      <tr class="detail1">
      <td align="left" valign="middle">
      DipPM15PC
      </td>
      <td align="left" valign="middle">
      <span class="">
      1559|
      <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559" title="NAN ">
      <img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
      [Project Costs] </a>
      </span>
      <span class="selected">
      [progress]
      </span>
      </td>
      <td align="left" valign="middle">
      <span class="disable">
      </span>
      <center style="display: none">
      </center>
      </td>
      <td align="center" valign="middle">
      </td>
      <td align="center" valign="middle">
      </td>
      </tr>
      </tbody>











      share|improve this question















      I'm trying to get the href from this string, but I can't because it has space inside the link. I try to do it from regex but I'm not an expert in regex. I tried using an example from the internet but I didn't get the value I was after.



      <table class="grid border" cellspacing="0" border="0" id="ctl00_ContentBody_grvStudentResult" style="width:100%;border-collapse:collapse;">
      <tbody>
      <tr>
      <th align="left" valign="middle" scope="col">Code</th>
      <th align="left" valign="middle" scope="col">Subject</th>
      <th align="left" valign="middle" scope="col">Status</th>
      <th align="center" valign="middle" scope="col">Score</th>
      <th align="center" valign="middle" scope="col">Result Date</th>
      </tr>
      <tr class="detail1">
      <td align="left" valign="middle">
      DipPM15PQ
      </td>
      <td align="left" valign="middle">
      <span class="">
      1561|
      <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved ">
      <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
      [Project Quality] </a>
      </span>
      <span class="selected">
      </span>
      </td>
      <td align="left" valign="middle">
      <span class="enable">
      Competent
      </span>
      <center style="display: none">
      <span disabled="disabled"><input id="ctl00_ContentBody_grvStudentResult_ctl02_chkAP" type="checkbox" name="ctl00$ContentBody$grvStudentResult$ctl02$chkAP" checked="checked" disabled="disabled"><label for="ctl00_ContentBody_grvStudentResult_ctl02_chkAP"> </label></span>
      </center>
      </td>
      <td align="center" valign="middle">
      75.00
      </td>
      <td align="center" valign="middle">
      11/11/2018
      </td>
      </tr>
      <tr class="detail1">
      <td align="left" valign="middle">
      DipPM15PC
      </td>
      <td align="left" valign="middle">
      <span class="">
      1559|
      <a onclick="return hs.htmlExpand( this, { objectType: 'iframe', width: 800, height: 600, outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559" title="NAN ">
      <img alt="" style="display: online" src="../Images/Common/r_.gif" border="0">
      [Project Costs] </a>
      </span>
      <span class="selected">
      [progress]
      </span>
      </td>
      <td align="left" valign="middle">
      <span class="disable">
      </span>
      <center style="display: none">
      </center>
      </td>
      <td align="center" valign="middle">
      </td>
      <td align="center" valign="middle">
      </td>
      </tr>
      </tbody>








      php html regex tags






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 17 at 5:45









      Nick Parsons

      2,3362518




      2,3362518










      asked Nov 17 at 5:36









      Gustavo Filgueiras

      5016




      5016
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:



          $doc = new DOMDocument();
          $doc->loadHTML($html);
          $anchors = $doc->getElementsByTagName('a');
          foreach ($anchors as $a) {
          $urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
          }
          foreach ($urls as $url) {
          echo $url;
          }


          Output



          DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561 
          DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559


          Demo on 3v4l.org



          If you have to use regex, this will work for your sample data:



          preg_match_all('/href="([^"]+)/', $html, $matches);
          print_r($matches[1]);


          Output:



          Array ( 
          [0] => DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561
          [1] => DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559
          )


          Demo on 3v4l.org






          share|improve this answer























          • Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
            – Gustavo Filgueiras
            Nov 17 at 6:20










          • @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
            – Nick
            Nov 17 at 7:06


















          up vote
          0
          down vote













          I'm not expert but this work for me



          $string ='<a onclick="return hs.htmlExpand( this, {  objectType: 'iframe', width: 800, height: 600,  outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved "> 
          <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
          [Project Quality] </a>';
          preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );

          $urls=array();//array of link
          foreach($match as $m){
          if (isset($m[0])) {
          $url= $m[0];
          }}





          share|improve this answer








          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thanks for help me brow! But it's dosen't work well =/
            – Gustavo Filgueiras
            Nov 17 at 5:54










          • @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
            – Davіd
            Nov 17 at 6:01










          • this regex used on WordPress to get all image from a post.you can use this to get any attribute.
            – Mahfuzar Rahman
            Nov 17 at 6:01












          • Yes, sorry! So i need all the links insde the array, like
            – Gustavo Filgueiras
            Nov 17 at 6:07










          • $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
            – Gustavo Filgueiras
            Nov 17 at 6:08











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348556%2fhow-to-get-href-value-from-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:



          $doc = new DOMDocument();
          $doc->loadHTML($html);
          $anchors = $doc->getElementsByTagName('a');
          foreach ($anchors as $a) {
          $urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
          }
          foreach ($urls as $url) {
          echo $url;
          }


          Output



          DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561 
          DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559


          Demo on 3v4l.org



          If you have to use regex, this will work for your sample data:



          preg_match_all('/href="([^"]+)/', $html, $matches);
          print_r($matches[1]);


          Output:



          Array ( 
          [0] => DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561
          [1] => DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559
          )


          Demo on 3v4l.org






          share|improve this answer























          • Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
            – Gustavo Filgueiras
            Nov 17 at 6:20










          • @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
            – Nick
            Nov 17 at 7:06















          up vote
          1
          down vote



          accepted










          A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:



          $doc = new DOMDocument();
          $doc->loadHTML($html);
          $anchors = $doc->getElementsByTagName('a');
          foreach ($anchors as $a) {
          $urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
          }
          foreach ($urls as $url) {
          echo $url;
          }


          Output



          DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561 
          DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559


          Demo on 3v4l.org



          If you have to use regex, this will work for your sample data:



          preg_match_all('/href="([^"]+)/', $html, $matches);
          print_r($matches[1]);


          Output:



          Array ( 
          [0] => DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561
          [1] => DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559
          )


          Demo on 3v4l.org






          share|improve this answer























          • Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
            – Gustavo Filgueiras
            Nov 17 at 6:20










          • @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
            – Nick
            Nov 17 at 7:06













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:



          $doc = new DOMDocument();
          $doc->loadHTML($html);
          $anchors = $doc->getElementsByTagName('a');
          foreach ($anchors as $a) {
          $urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
          }
          foreach ($urls as $url) {
          echo $url;
          }


          Output



          DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561 
          DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559


          Demo on 3v4l.org



          If you have to use regex, this will work for your sample data:



          preg_match_all('/href="([^"]+)/', $html, $matches);
          print_r($matches[1]);


          Output:



          Array ( 
          [0] => DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561
          [1] => DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559
          )


          Demo on 3v4l.org






          share|improve this answer














          A better way to parse HTML is to use DOMDocument. You can use it to process your HTML and find the hrefs from all the <a> tags in your HTML. I'm assuming your HTML is in a variable called $html:



          $doc = new DOMDocument();
          $doc->loadHTML($html);
          $anchors = $doc->getElementsByTagName('a');
          foreach ($anchors as $a) {
          $urls = $a->attributes->getNamedItem('href')->nodeValue . "n";
          }
          foreach ($urls as $url) {
          echo $url;
          }


          Output



          DetailResults.aspx?sid=90651&id=1769095&nsub= [Project Quality] &Subjectid=1561 
          DetailResults.aspx?sid=90898&id=1769088&nsub= [Project Costs] &Subjectid=1559


          Demo on 3v4l.org



          If you have to use regex, this will work for your sample data:



          preg_match_all('/href="([^"]+)/', $html, $matches);
          print_r($matches[1]);


          Output:



          Array ( 
          [0] => DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561
          [1] => DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559
          )


          Demo on 3v4l.org







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 17 at 7:05

























          answered Nov 17 at 6:16









          Nick

          19k41433




          19k41433












          • Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
            – Gustavo Filgueiras
            Nov 17 at 6:20










          • @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
            – Nick
            Nov 17 at 7:06


















          • Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
            – Gustavo Filgueiras
            Nov 17 at 6:20










          • @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
            – Nick
            Nov 17 at 7:06
















          Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
          – Gustavo Filgueiras
          Nov 17 at 6:20




          Hi Brow, thanks for help me ! :) So i check your demo link and it's really work... But for this project, i really need to do by regex =/
          – Gustavo Filgueiras
          Nov 17 at 6:20












          @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
          – Nick
          Nov 17 at 7:06




          @GustavoFilgueiras regex really isn't a good way to parse HTML. But if you have to, I've added a possible solution to my answer.
          – Nick
          Nov 17 at 7:06












          up vote
          0
          down vote













          I'm not expert but this work for me



          $string ='<a onclick="return hs.htmlExpand( this, {  objectType: 'iframe', width: 800, height: 600,  outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved "> 
          <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
          [Project Quality] </a>';
          preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );

          $urls=array();//array of link
          foreach($match as $m){
          if (isset($m[0])) {
          $url= $m[0];
          }}





          share|improve this answer








          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thanks for help me brow! But it's dosen't work well =/
            – Gustavo Filgueiras
            Nov 17 at 5:54










          • @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
            – Davіd
            Nov 17 at 6:01










          • this regex used on WordPress to get all image from a post.you can use this to get any attribute.
            – Mahfuzar Rahman
            Nov 17 at 6:01












          • Yes, sorry! So i need all the links insde the array, like
            – Gustavo Filgueiras
            Nov 17 at 6:07










          • $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
            – Gustavo Filgueiras
            Nov 17 at 6:08















          up vote
          0
          down vote













          I'm not expert but this work for me



          $string ='<a onclick="return hs.htmlExpand( this, {  objectType: 'iframe', width: 800, height: 600,  outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved "> 
          <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
          [Project Quality] </a>';
          preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );

          $urls=array();//array of link
          foreach($match as $m){
          if (isset($m[0])) {
          $url= $m[0];
          }}





          share|improve this answer








          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.


















          • Thanks for help me brow! But it's dosen't work well =/
            – Gustavo Filgueiras
            Nov 17 at 5:54










          • @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
            – Davіd
            Nov 17 at 6:01










          • this regex used on WordPress to get all image from a post.you can use this to get any attribute.
            – Mahfuzar Rahman
            Nov 17 at 6:01












          • Yes, sorry! So i need all the links insde the array, like
            – Gustavo Filgueiras
            Nov 17 at 6:07










          • $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
            – Gustavo Filgueiras
            Nov 17 at 6:08













          up vote
          0
          down vote










          up vote
          0
          down vote









          I'm not expert but this work for me



          $string ='<a onclick="return hs.htmlExpand( this, {  objectType: 'iframe', width: 800, height: 600,  outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved "> 
          <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
          [Project Quality] </a>';
          preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );

          $urls=array();//array of link
          foreach($match as $m){
          if (isset($m[0])) {
          $url= $m[0];
          }}





          share|improve this answer








          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          I'm not expert but this work for me



          $string ='<a onclick="return hs.htmlExpand( this, {  objectType: 'iframe', width: 800, height: 600,  outlineWhileAnimating: true, preserveContent: false } )" href="DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" title="Approved "> 
          <img alt="" style="display: online" src="../Images/Common/r_Approved.gif" border="0">
          [Project Quality] </a>';
          preg_match_all( '~<a .*?href=['"](.*?)['"].*?>~', $string, $match );

          $urls=array();//array of link
          foreach($match as $m){
          if (isset($m[0])) {
          $url= $m[0];
          }}






          share|improve this answer








          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 17 at 5:48









          Mahfuzar Rahman

          667




          667




          New contributor




          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Mahfuzar Rahman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.












          • Thanks for help me brow! But it's dosen't work well =/
            – Gustavo Filgueiras
            Nov 17 at 5:54










          • @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
            – Davіd
            Nov 17 at 6:01










          • this regex used on WordPress to get all image from a post.you can use this to get any attribute.
            – Mahfuzar Rahman
            Nov 17 at 6:01












          • Yes, sorry! So i need all the links insde the array, like
            – Gustavo Filgueiras
            Nov 17 at 6:07










          • $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
            – Gustavo Filgueiras
            Nov 17 at 6:08


















          • Thanks for help me brow! But it's dosen't work well =/
            – Gustavo Filgueiras
            Nov 17 at 5:54










          • @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
            – Davіd
            Nov 17 at 6:01










          • this regex used on WordPress to get all image from a post.you can use this to get any attribute.
            – Mahfuzar Rahman
            Nov 17 at 6:01












          • Yes, sorry! So i need all the links insde the array, like
            – Gustavo Filgueiras
            Nov 17 at 6:07










          • $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
            – Gustavo Filgueiras
            Nov 17 at 6:08
















          Thanks for help me brow! But it's dosen't work well =/
          – Gustavo Filgueiras
          Nov 17 at 5:54




          Thanks for help me brow! But it's dosen't work well =/
          – Gustavo Filgueiras
          Nov 17 at 5:54












          @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
          – Davіd
          Nov 17 at 6:01




          @GustavoFilgueiras Can you elaborate on exactly what doesn't work well, and how you'd like it to work better?
          – Davіd
          Nov 17 at 6:01












          this regex used on WordPress to get all image from a post.you can use this to get any attribute.
          – Mahfuzar Rahman
          Nov 17 at 6:01






          this regex used on WordPress to get all image from a post.you can use this to get any attribute.
          – Mahfuzar Rahman
          Nov 17 at 6:01














          Yes, sorry! So i need all the links insde the array, like
          – Gustavo Filgueiras
          Nov 17 at 6:07




          Yes, sorry! So i need all the links insde the array, like
          – Gustavo Filgueiras
          Nov 17 at 6:07












          $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
          – Gustavo Filgueiras
          Nov 17 at 6:08




          $url = $url = "DetailResults.aspx?sid=90651&amp;id=1769095&amp;nsub= [Project Quality] &amp;Subjectid=1561" $url = "DetailResults.aspx?sid=90898&amp;id=1769088&amp;nsub= [Project Costs] &amp;Subjectid=1559"
          – Gustavo Filgueiras
          Nov 17 at 6:08


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53348556%2fhow-to-get-href-value-from-string%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Paul Cézanne

          UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

          Angular material date-picker (MatDatepicker) auto completes the date on focus out