public function attrPHP($attr, $code)
{
if (!is_null($code)) {
$value = '<' . '?php ' . $code . ' ?' . '>';
// TODO tempolary solution
// http://code.google.com/p/phpquery/issues/detail?id=17
// if (function_exists('mb_detect_encoding') && mb_detect_encoding($value) == 'ASCII')
// $value = mb_convert_encoding($value, 'UTF-8', 'HTML-ENTITIES');
}
foreach ($this->stack(1) as $node) {
if (!is_null($code)) {
// $attrNode = $this->DOM->createAttribute($attr);
$node->setAttribute($attr, $value);
// $attrNode->value = $value;
// $node->appendChild($attrNode);
} elseif ($attr == '*') {
// jQuery diff
$return = array();
foreach ($node->attributes as $n => $v) {
$return[$n] = $v->value;
}
return $return;
} else {
return $node->getAttribute($attr);
}
}
return $this;
}