Menu

#13 tag with inner xml

open
nobody
None
2
2011-03-27
2011-03-27
luca capra
No

This not really a bug, but a workaround.
I generate an odt document prepared from users.
Many times there are tags like:
{<text:span text:style-name="T34">M</text:span>y<text:span text:style-name="T34">Tag</text:span>}

I've solved in the way that follow, hope could be useful.

<?php
$data = array(
"tag"=>"value",
);
$odf = new odf(...);

$fulltext = $odf->__toString()
preg_match_all("~\{([^{]+)\}~ium", $fulltext, $res);

foreach($tokens[1] as $token)
{

if(key_exists($tokenx = strip_tags($token), $data)){
preg_match_all("~<[^<]*>([^<>]*)~iu", $token, $res);
$pieces = $res[1];
$tmpk = implode("", $pieces);
// echo "<p>".htmlspecialchars($token)." -> $tmpk";
if(strlen(trim($tmpk)) > 0 && key_exists( $tmpk, $data ))
{
$data[$token] = $data[$tmpk];
}
}
else
if(! key_exists( $token , $data) )
{
$data[ $token ] = "";
}
}
// go on rendering
foreach($data as $k=>$var)
$odf->setVars($k, $var);

$odf->exportAsAttachedFile();
?>

Discussion

  • luca capra

    luca capra - 2011-03-27

    // SORRY, typos writing code :(
    // those lines following has been corrected
    ...
    $fulltext = $odf->__toString();
    preg_match_all("~\{([^{]+)\}~ium", $fulltext, $tokens);

    foreach($tokens[1] as $token).
    {
    ...

     
  • luca capra

    luca capra - 2011-03-27
    • priority: 5 --> 2
     

Log in to post a comment.