Okay, the output buffering stuff is a really helpful clue that I hadn't stumbled upon yet in all that other searches I was doing! This is the code for parsing my xml file, so the output of all this is what I need to run the find/replace function on:
<?php
//Initialize the XML parser
$parser=xml_parser_create();
//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
switch($element_name)
{
case "item":
echo "";
break;
case "title":
echo "";
break;
case "description":
echo "";
break;
case "image":
echo "";
}
}
//Function to use at the end of an element
function stop($parser,$element_name)
{
echo "";
}
//Function to use when finding character data
function char($parser,$data)
{
echo $data;
}
//Specify element handler
xml_set_element_handler($parser,"start","stop");
//Specify data handler
xml_set_character_data_handler($parser,"char");
//Open XML file
$fp=fopen("xml/page_artwork_Item_Slider.xml","r");
//Read data
while ($data=fread($fp,4096))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
//Free the XML parser
xml_parser_free($parser);
?>
So I've been checking out the output buffering tutorial you recommended, and some other links I found..... trying to find similar cases since I learn best by working backwards from examples. Here is one way I have tried integrating my preg_replace code with output buffering and my xml parser. It doesn't work at all (it does display my xml data, but just none of the image reformatting), so as you suggested, I figure I need to find a way to output the result of the xml parser to one variable and then call that variable on the "$find = ??? ;" line. I have a feeling that the code below is conflating a couple approaches. I put question marks and commenting in places where I know for sure I'm screwed up....
<?php
//Initialize the XML parser
$parser=xml_parser_create();
//Function to use at the start of an element
function start($parser,$element_name,$element_attrs)
{
switch($element_name)
{
case "item":
echo " ";
break;
case "title":
echo " ";
break;
case "description":
echo " ";
break;
case "link":
echo " ";
break;
case "img":
echo " ";
}
}
//Function to use at the end of an element
function stop($parser,$element_name)
{
echo "<br />";
}
//Function to use when finding character data
function char($parser,$data)
{
echo $data;
}
//Specify element handler
xml_set_element_handler($parser,"start","stop");
//Specify data handler
xml_set_character_data_handler($parser,"char");
//Open XML file
$fp=fopen("xml/page_artwork_Item_Slider.xml","r");
//Read data
while ($data=fread($fp,4096))
{
xml_parse($parser,$data,feof($fp)) or
die (sprintf("XML Error: %s at line %d",
xml_error_string(xml_get_error_code($parser)),
xml_get_current_line_number($parser)));
}
function htmlformat_output($buffer) // ???still not sure where to put this function in relation to the rest of the xml parsing code //
{
$find = ??? ; // ???still trying to figure out what to put here... tried a few things already... //
$replace = '<img src="$1" border="0" class="floatleft" />';
$buffer = preg_replace('~<image.*?>(.*?)</image>~', $replace, $find);
return $buffer;
}
ob_start("htmlformat_output");
ob_end_flush();
//Free the XML parser
xml_parser_free($parser); // ???still not sure where to put this in relation to the rest of the xml parsing code //
?>