user684202
user684202

Reputation:

Eval() problem in PHP

Quite some time ago I wrote a RSS parser. It worked fine until now, when I turned my error and notice reporting on. Currently I keep getting quite a lot of notices that tell me that something is wrong in the function. I tried solving this problem on my own, but I had no success. Could You please help me with this error?

The error:

Notice: Undefined index: RSS in C:\xampp\htdocs\Dropbox\RECtus\System\sysFiles\libarys\myRSSParser.lib(103) : eval()'d code on line 1

Notice: Undefined index: LINK in C:\xampp\htdocs\Dropbox\RECtus\System\sysFiles\libarys\myRSSParser.lib(103) : eval()'d code on line 1

The script:

function parseData($parser, $data) {
        if(!trim($data)) return;
        $RSS = '';
        $evalcode = "\$this->output";

        foreach($this->tags as $tag) {
            if(is_array($tag)) {
                list($tagname, $indexes) = each($tag);

                $evalcode .= "[\"$tagname\"]";
                if(!isset(${$tagname})) ${$tagname} = '';
                if(${$tagname}) $evalcode .= "[" . (${$tagname} - 1) . "]";
                if($indexes) extract($indexes); 
            } else {
                if(preg_match("/^([A-Z]+):([A-Z]+)$/", $tag, $matches)) {
                    $evalcode .= "[\"$matches[1]\"][\"$matches[2]\"]";
                } else {
                    $evalcode .= "[\"$tag\"]";
                }
            }
        }
        eval("$evalcode = $evalcode . '" . addslashes($data) . "';");
}

Line 103 is the eval() line.

Upvotes: 0

Views: 288

Answers (1)

Pascal MARTIN
Pascal MARTIN

Reputation: 400912

Why are you using eval() ?

It seems you're just trying to concatenate portions of string, no ?

If so, why not just... concatenate portions of strings ?


Basically, you should be able to do something like this :
$this->output = array();
$this->output['...'] = 'some string';
$this->output['...'] = array();
$this->output['...']['...'] = 'some other string';

Upvotes: 2

Related Questions