You are here: Re: PHP saving embedded HTML in XML « PHP Programming Language « IT news, forums, messages
Re: PHP saving embedded HTML in XML

Posted by dcrackel on 02/21/07 22:50

I have 2 different fixes, one is to a PHP function to swap the chaters
as needed:

function fixXML($string){

for($i=1; $i < strlen($string);$i++) {
$subs1 = substr ($string, $i, 4);

switch ($subs1) {
case "&gt;":
$string = substr ($string, 0, $i) . ">" . substr ($string, $i +4,
strlen($string));
break;
case "&lt;":
$string = substr ($string, 0, $i) . "<" . substr ($string, $i +4,
strlen($string));
break;
}
}// end for
return $string;
}

<... code ..>

print fixXML($dom->saveXML());


and another way it can be done in the XSL. I thought this method was
allot messer.... and you would need to call for each charater you need
to swap out.

Snips from test.xsl
--------

<xsl:variable name="myString" select="HEADLINE" />
<xsl:variable name="myNewString">
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="$myString" />
<xsl:with-param name="substringIn" select="'&lt;'"/>
<xsl:with-param name="substringOut" select="'%3C'"/>

</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat(' input: ',$myString,' output: ',
$myNewString)" />


<xsl:template name="SubstringReplace">
<xsl:param name="stringIn" />
<xsl:param name="substringIn" />
<xsl:param name="substringOut" />
<xsl:choose>
<xsl:when test="contains($stringIn,$substringIn)">
<xsl:value-of select="concat(substring-before($stringIn,
$substringIn),$substringOut)" />
<xsl:call-template name="SubstringReplace">
<xsl:with-param name="stringIn" select="substring-after($stringIn,
$substringIn)" />
<xsl:with-param name="substringIn" select="$substringIn" />
<xsl:with-param name="substringOut" select="$substringOut" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$stringIn" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>



I hope this helps someone.

good luck

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация