1

I would like to change that content:

Cambio turno (FL) HMLN 16:00-20:00 del 08/09/2018 con (FL) HMLN 15:00-19:00 del 05/09/2018

into:

<a href="prova.it">Cambio turno (FL) HMLN 16:00-20:00 del 08/09/2018 con (FL) HMLN 15:00-19:00 del 05/09/2018</a>

This is an extract from the html page:

<td class="tdReset">
  <table id="ctl00_ctl00_mainContent_bodyContent_TblOperazioni_8529448" class="tblReset">
    <tbody>
      <tr>
        <td operazione="accetta"><input id="ctl00_ctl00_mainContent_bodyContent_chkAccetta_8529448" name="ctl00$ctl00$mainContent$bodyContent$chkAccetta_8529448" onclick="SelezioneUnivocaAccetta(this);AccettaRifiutaStessaRichiesta(this);" tabindex="0" type="checkbox"><label for="ctl00_ctl00_mainContent_bodyContent_chkAccetta_8529448">Accetta</label></td>
      </tr>
      <tr>
        <td operazione="rifiuta">
          <input id="ctl00_ctl00_mainContent_bodyContent_chkRifiuta_8529448" name="ctl00$ctl00$mainContent$bodyContent$chkRifiuta_8529448" onclick="AccettaRifiutaStessaRichiesta(this);" tabindex="0" type="checkbox">
          <label for="ctl00_ctl00_mainContent_bodyContent_chkRifiuta_8529448">Rifiuta</label>
        </td>
      </tr>
    </tbody>
  </table>
</td>
<td>sab 01/09/2018</td>
<td>Proposta</td>
<td><span style="padding-left:15px;"> Jhon</span></td>
<td class="textWrap">Cambio turno (FL) HMLN 16:00-20:00 del 08/09/2018 con (FL) HMLN 15:00-19:00 del 05/09/2018</td>
<td></td>
<td></td>

The code I created in PHP is as follows:

 $xpR=new DOMXPath( $dom_richieste_r );
  $operazione_select= $xpR->query( '//label[contains(.,"Accetta")]' );
  if( !empty( $operazione_select )){
    foreach( $operazione_select as $node2 ){
       //$node2->parentNode->parentNode->parentNode->parentNode->parentNode->firstChild->nextSibling->nextSibling->nextSibling->nextSibling->C14N(); // get Cambio turno (FL) HMLN 16:00-20:00 del 08/09/2018 con (FL) HMLN 15:00-19:00 del 05/09/2018 

       $newelement = $dom_richieste_r->createElement('a', 'prova'); 
       $newelement->setAttribute("href", "http://prova.it");
       $link_1=$node2->parentNode->parentNode->parentNode->parentNode->parentNode->firstChild->nextSibling->nextSibling->nextSibling->nextSibling;

      $link_1->replaceChild($newelement, $link_1);

    }
   } 
0

1 Answer 1

1

I don't know why you have to select the node in question relative to the Accept button but you can do it with a single XPath query like this

//*[td/table/tbody/tr/td/label[contains(.,"Accetta")]]/td[5]

XPath Demo

and then replace the inner text like this:

$dom = new DOMDocument();
$dom->loadHTML($str);
$xpath = new DOMXPath($dom);
$operazione_select = $xpath->query('//*[td/table/tbody/tr/td/label[contains(.,"Accetta")]]/td[5]');
foreach ($operazione_select as $node) {
    //create link
    $newlink = $dom->createElement('a', $node->nodeValue);
    $newlink->setAttribute('href', 'http://prova.it');
    $node->removeChild($node->childNodes->item(0));
    $node->appendChild($newlink);    
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.