Forum


Replies: 5   Views: 31
How to add url link in text type placeholder

Posted by fairshareitservices  · 14-01-2025 - 05:48

Below is our function to add link to a placeholder - 

$fomattedURLWordFragment = addUrlLink($value,$templateDocx,$placeHolderName);
$templateDocx->replaceVariableByWordFragment(array('placeHolderName' => $fomattedURLWordFragment), array('type' => 'inline', 'target' => 'document'));

function addUrlLink($inputText,$templateDocx,$placeHolderName){ Â  Â 
    echo "In addUrlLink";
    $docx = new CreateDocx();
    $wf = new WordFragment($docx);

    //preg_match('/<link>(.*?)<\/link>/', $inputText, $matches);
    
    $text = array();
    //print_r($matches); //die();
    //$url = $matches[1]; // This will contain 'www.hdfcfund.com'
    $url = 'www.hdfcfund.com';
    $link = new WordFragment($docx);
    //$link->addLink($matches[0], array('url'=> $url, 'color' => '0000FF', 'u' => 'single'));
    $link->addLink($inputText, array('url'=> $url, 'color' => '0000FF'));
    $text[] = $link;
    
    //print_r($text); //die();
    $wf->addText($text, array('font' => 'Cambria', 'fontSize' => 6.5));
    return $wf;

}

This does not add link to the placeholder variable. Please correct the above code.