Jump to content

Recommended Posts

Thanks everyone for all the help you've been.

Now, I'm having a problem in that, when I turn my code into a class, it fails to instantiate. I've looked at the documentation for how PHP treats objects--fairly simple--and I'm stumped. I know I'm missing something obvious.

Any ideas?

 

<?php

class eventList	
{
$stack = array();
$tagname="";
function create($filename)
{	
	if (! ($xmlparser = xml_parser_create()) )
	{ 
	   die ("Cannot create parser");
	}

	function start_tag($parser, $name, $attribs) 
	{
		global $tagname;
		$tagname = $name;
	}
	function end_tag($parser, $name) {
	}
	function tag_contents($parser, $data) {
		global $tagname;
		global $stack;
		$stack[$tagname]=$data;
	}
	xml_set_element_handler($xmlparser, "start_tag", "end_tag");
	xml_set_character_data_handler($xmlparser, "tag_contents");

	if (!($fp = fopen($filename, "r"))) 
	{ 
		die("cannot open ".$filename); 
	}

	while ($data = fread($fp, 4096))
	{
	 	$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
	   	if (!xml_parse($xmlparser, $data, feof($fp))) 
		{
		  	$reason = xml_error_string(xml_get_error_code($xmlparser));
		  	$reason .= xml_get_current_line_number($xmlparser);
		  	die($reason);
	   	}
	}
	xml_parser_free($xmlparser);
}
}
$event1=new eventList();
$event1->create("http://www.example.com/rss.xml");

?>

Link to comment
https://forums.phpfreaks.com/topic/61003-solved-converting-object-to-class/
Share on other sites

class eventList	
{
var $stack = array();
var $tagname="";
function create($filename)
{	
	if (! ($xmlparser = xml_parser_create()) )
	{ 
	   die ("Cannot create parser");
	}

	function start_tag($parser, $name, $attribs) 
	{
		global $tagname;
		$tagname = $name;
	}
	function end_tag($parser, $name) {
	}
	function tag_contents($parser, $data) {
		global $tagname;
		global $stack;
		$stack[$tagname]=$data;
	}
	xml_set_element_handler($xmlparser, "start_tag", "end_tag");
	xml_set_character_data_handler($xmlparser, "tag_contents");

	if (!($fp = fopen($filename, "r"))) 
	{ 
		die("cannot open ".$filename); 
	}

	while ($data = fread($fp, 4096))
	{
	 	$data=eregi_replace(">"."[[:space:]]+"."<","><",$data);
	   	if (!xml_parse($xmlparser, $data, feof($fp))) 
		{
		  	$reason = xml_error_string(xml_get_error_code($xmlparser));
		  	$reason .= xml_get_current_line_number($xmlparser);
		  	die($reason);
	   	}
	}
	xml_parser_free($xmlparser);
}
}
$event1=new eventList();
$event1->create("http://www.example.com/rss.xml");

?>

 

Parse error for one, turn on display_errors and error_reporting to E_ALL and report any more errors.

Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test.

:(

Is the error tracking something I can still do on shared hosting?

 

Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test.

:(

Is the error tracking something I can still do on shared hosting?

 

 

Should be

 

www.php.net/display_errors

www.php.net/error_reporting

 

It is good to be disabled in production enviroments, but for testing you want them to show all errors.

Sorry, I wanted to change my post, but I missed the time limit. The PHP install on my laptop has consistently failed time and again. Not sure why. Never had the time to figure it out. So, I have to upload my code to a shared hosting server to test.

:(

Is the error tracking something I can still do on shared hosting?

 

 

Should be

 

www.php.net/display_errors

www.php.net/error_reporting

 

It is good to be disabled in production enviroments, but for testing you want them to show all errors.

 

Okay, I added

error_reporting(E_ALL);

error_reporting(E_PARSE);

to the top of my script. No screen output. I checked my logs with the hosting company: nothing yet. On the other hand, the logs they (Globat) supply me look like they came out of a chron job so I may not get any error information until tomorrow.

 

 

Okay,

I put the following code at the top of my script, including the parse error line separately because evidently E_ALL doesn't pick those up:

ini_set("display_errors", "on");

error_reporting(E_ALL);

error_reporting(E_PARSE);

$p = getcwd();

error_log("ERRORS!", 3, $p."/my-errors.log");

I was hoping to redirect the error log to my working directory, but I'm still coming up with bupkiss.

 

 

Okay,

I put the following code at the top of my script, including the parse error line separately because evidently E_ALL doesn't pick those up:

ini_set("display_errors", "on");

error_reporting(E_ALL);

error_reporting(E_PARSE);

$p = getcwd();

error_log("ERRORS!", 3, $p."/my-errors.log");

Before you say it--yes, I know that error log on line 5 was pointless.

I tried both ini_set('display_errors','1'); and ini_set("display_errors", "on");

Any idea why these won't display to the page?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.