Forum


Replies: 5   Views: 224
How to add url link in text type placeholder
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

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.