views:

213

answers:

3

Hi all.

I'm trying to modify a part of a PHP script structured like this barebone example

<-- part A -->
function modify_B($string)
{
    some code to modify part B
}
<-- end A -->

<-- part B --> 
<container>some XML</container>
<-- end B -->

<-- part C -->
<-- end C -->

I'd like to modify part B without changing the rest of the file, because A and B are the logic of the script which should not change.

Could somebody help me? Thank you in advance for your help.

+1  A: 

It looks like, from your example, it's just some string data XML. So load the content into a string somehow (either set a variable with standard string notation, or read it from the contents of a separate file), modify the string according to your whims, and then echo the string to the output. Then it's not a problem of being self-modifying anymore. It's just a matter of being data-driven.

fennec
A: 

Do you mean that the XML is outside of your PHP <? ?> script tags? So you want to modify the text that's about to be output by the PHP script?

If that's the case, remember that anything outside of script tags is just treated as a string, which PHP outputs as if you had written echo $string;. So just save your changed data in a string variable, and echo it.

JW
A: 

Or if you need persistence in the changes, put "B" in a file and include or read it.

Wes Groleau