Hi, I downloaded the following code off of phpwizard.net, it is to send emails with attahced files. Hoever I can not figure out how to use it, if any of you know how that would be great, I need help. Thanx!
<?
/*
void html_parse(string html, string element_handler, string tag)
This function opens and parses $html_file for $tag
and returns its content and its attributes to the
callback function $element_handler.
$element_handler is a custom funtion which acts upon
the content and the attributes of $tag and gets called
everytime $tag is closed. It must accept the following parameters:
- $attributes (attributes of $tag
- $content (content of the element $tag)
Addition 1999-01-22:
$html_file no longer needs to be a file but can also be a string.
/
function html_parse($html_file, $element_handler, $tag)
{
/
This is now quite fast (< 1 sec), but it loads the entire file into memory.
*/
if (file_exists($html_file))
{
$fd = fopen($html_file, "r") or die( "Error: Unable to open file $html_file");
$file_content = fread($fd, filesize($html_file));
fclose( $fd );
$file_content = stripslashes($file_content);
}
else
{
$file_content = $html_file;
}
while ($full_tag = strstr($file_content, "<$tag"))
{
$full_tag = substr($full_tag, 0, strpos($full_tag, "</$tag>")+strlen($tag)+3);
$open_tag = substr($full_tag, 0, strpos($full_tag, ">")+1);
$open_tag = ereg_replace( "[<>]|$tag", "", $open_tag);
// Split the string into key/value pairs: first split it into key=value,
// later into a hash.
$tmp_array = split ( "[$\"] +", $open_tag);
for ($i=0; $i<count($tmp_array); $i++)
{
$tmp_array[$i] = trim($tmp_array[$i]);
$tmp_array[$i] = ereg_replace( "\"", "", $tmp_array[$i]);
$tmp_attribs = split( "=", $tmp_array[$i]);
for ($j=0; $j<count($tmp_attribs); $j++)
{
// Don't add empty pairs 🙂
if ($tmp_attribs[$j] != "" && $tmp_attribs[$j+1] != "")
{
$attribs[trim($tmp_attribs[$j])] = trim($tmp_attribs[$j+1]);
}
}
}
$content = substr ($full_tag, strpos($full_tag, ">"));
$content = substr($content, 1, strpos($content, "</$tag>")-1);
$element_handler($attribs, trim($content));
$file_content = substr($file_content, strpos($file_content, "</$tag>")+strlen($tag)+3);
}
}
/
Example usage:
require("html_parse.php3");
function my_handler($attribs, $content)
{
echo $content;
}
html_parse("index.html", "my_handler", "title");
/
?>