/** * Set a Template value * * @param mixed $search * @param mixed $replace */ public function setValue($search, $replace) { if (substr($search, 0, 2) !== '${' && substr($search, -1) !== '}') { $search = '${' . $search . '}'; } if (!is_array($replace)) { $replace = utf8encode_dummy($replace); } $this->_documentXML = str_replace($search, $replace, $this->_documentXML); }
/** * Add a PreserveText Element * * @param string $text * @param mixed $styleFont * @param mixed $styleParagraph * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { $text = utf8encode_dummy($text); $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; }
/** * Add a PreserveText Element * * @param string $text * @param mixed $styleFont * @param mixed $styleParagraph * @return PHPWord_Section_Footer_PreserveText */ public function addPreserveText($text, $styleFont = null, $styleParagraph = null) { if ($this->_insideOf == 'footer' || $this->_insideOf == 'header') { $text = utf8encode_dummy($text); $ptext = new PHPWord_Section_Footer_PreserveText($text, $styleFont, $styleParagraph); $this->_elementCollection[] = $ptext; return $ptext; } else { trigger_error('addPreserveText only supported in footer/header.'); } }
/** * Add a Link Element * * @param string $linkSrc * @param string $linkName * @param mixed $styleFont * @return PHPWord_Section_Link */ public function addLink($linkSrc, $linkName = null, $styleFont = null) { $linkSrc = utf8encode_dummy($linkSrc); if (!is_null($linkName)) { $linkName = utf8encode_dummy($linkName); } $link = new PHPWord_Section_Link($linkSrc, $linkName, $styleFont); $rID = PHPWord_Media::addSectionLinkElement($linkSrc); $link->setRelationId($rID); $this->_elementCollection[] = $link; return $link; }
/** * Check if a string contains UTF8 data * * @param string $value * @return boolean */ public static function IsUTF8($value = '') { return utf8encode_dummy(utf8_decode($value)) === $value; }
/** * Add a Title Element * * @param string $text * @param int $depth * @return PHPWord_Section_Title */ public function addTitle($text, $depth = 1) { $text = utf8encode_dummy($text); $styles = PHPWord_Style::getStyles(); if (array_key_exists('Heading_' . $depth, $styles)) { $style = 'Heading' . $depth; } else { $style = null; } $title = new PHPWord_Section_Title($text, $depth, $style); $data = PHPWord_TOC::addTitle($text, $depth); $anchor = $data[0]; $bookmarkId = $data[1]; $title->setAnchor($anchor); $title->setBookmarkId($bookmarkId); $this->_elementCollection[] = $title; return $title; }