热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

3_PHP教程

3。{if(is_array($value)!$delete){foreach($valueas$suboption$subvalue){$this-{$option}[$suboption]$subvalue;}}else{$this-$option$value;}}}}}thesear
{
if (is_array($value) && ! $delete)
{
foreach ($value as $suboption => $subvalue)
{
$this->{$option}["$suboption"] = $subvalue;
}
}
else
{
$this->$option = $value;
}
}
}
}
}

// these are the functions, which are intended to be overriden in user classes

/**
*
* @param mixed
* @return object DomNode
* @access private
*/
function insertNewResult(&$metadata)
{
if ($this->xmlroot)
return $this->xmlroot->new_child($this->tagNameResult, NULL);
else
{
$this->xmlroot = $this->xmldoc->add_root($this->tagNameResult);
//PHP 4.0.6 had $root->name as tagname, check for that here...
if (!isset($this->xmlroot->{$this->tagname}))
{
$this->tagname = "name";
}
return $this->xmlroot;

}
}


/**
* to be written
*
* @param object DomNode $parent_row
* @param mixed $res
* @param mixed $key
* @param mixed &metadata
* @return object DomNode
* @access private
*/
function insertNewRow($parent_row, $res, $key, &$metadata)
{
return $parent_row->new_child($this->tagNameRow, Null);
}


/**
* to be written
*
* @param object DomNode $parent
* @param mixed $res
* @param mixed $key
* @param mixed &$metadata
* @param mixed &$subrow
* @return object DomNode
* @access private
*/
function insertNewElement($parent, $res, $key, &$metadata, &$subrow)
{
return $parent->new_child($metadata[$key]["name"], $this->xml_encode(trim$res[$key]));
}


/**
* to be written
*
* @param mixed $key
* @param mixed $value
* @param mixed &$metadata
* @access private
*/
function addTableInfo($key, $value, &$metadata) {

}

// end functions, which are intended to be overriden in user classes

// here come some helper functions...

/**
* make utf8 out of the input data and escape & with & and "<" with "<"
* (we assume that when there's no space after * I'm not sure, if this is the standard way, but it works for me.
*
* @param string text to be utfed.
* @access private
*/
function xml_encode ($text)
{
if (function_exists("iconv") && isset($this->encoding_from) && isset($this->encoding_to))
{
ini_set("track_errors",1);
$text = iconv($this->encoding_from,$this->encoding_to,ereg_replace("&","&",ereg_replace("<","<",$text)));

if (! isset($text) )
{
if (isset($php_errormsg))
{
$errormsg = "error: $php_errormsg";
}
else
{
$errormsg = "undefined iconv error, turn on track_errors in php.ini to get more details";
}
return PEAR::raiseError($errormsg,Null,PEAR_ERROR_DIE);
}
else {
return $text;
}
}
else
{
//$text = utf8_encode(ereg_replace("&","&",ereg_replace("<","<",$text)));
$text = trim(ereg_replace("&","&",ereg_replace("<","<",$text)));
// echo $text;
}
return $text;
}

//taken from kc@hireability.com at http://www.php.net/manual/en/function.array-merge-recursive.php
/**
* There seemed to be no built in function that would merge two arrays recursively and clobber
* any existing key/value pairs. Array_Merge() is not recursive, and array_merge_recursive
* seemed to give unsatisfactory results... it would append duplicate key/values.
*
* So here's a cross between array_merge and array_merge_recursive
**/
/**
*
* @param array first array to be merged
* @param array second array to be merged
* @return array merged array
* @access private
*/
function array_merge_clobber($a1,$a2)
{
if(!is_array($a1)
!is_array($a2)) return false;
$newarray = $a1;
while (list($key, $val) = each($a2))
{
if (is_array($val) && is_array($newarray[$key]))
{
$newarray[$key] = $this->array_merge_clobber($newarray[$key], $val);
}
else
{
$newarray[$key] = $val;
}
}
return $newarray;
}

/**
* Adds a xml string to $this->xmldoc.
* It's inserted on the same level as a "normal" resultset, means just as a children of
* if a xpath expression is supplied, it takes that for selecting only part of the xml-file
*
* the clean code works only with php 4.0.7
* for php4.0.6 :
* I found no cleaner method than the below one. it's maybe nasty (xmlObject->string->xmlObject),
* but it works. If someone knows how to add whole DomNodes to another one, let me know...
*
* @param string xml string
* @param mixed xpath either a string with the xpath expression or an array with "xpath"=>xpath expression and "root"=tag/subtag/etc, which are the tags to be inserted before the result
* @access private
*/

function doXmlString2Xml ($string,$xpath = Null)
{

//check if we have a recent domxml. otherwise use the workaround...
$version = explode(".",phpversion());

if (! ($version[0] <= 4 and $version[1] <= 0 and $version[2] <7) ){

if (is_array($xpath))
{
if (isset($xpath["root"]))
{
$root = $xpath["root"];
}
$xpath = $xpath["xpath"];
}

$tmpxml = xmldoc($string);
$subroot = $this->xmlroot;

if (isset($root))
{
$roots = explode("/",$root);
foreach ($roots as $rootelement)
{
if ( strlen($rootelement) > 0 )
{
$subroot = $subroot->new_child($rootelement,"");
}
}
}


//$this->xmlroot->addchild does some strange things when added nodes from xpath.... so this comment helps out
$newchild = $subroot->add_child($this->xmldoc->create_comment("the purpose of this comment is a workaround in sql2php.php line ".__LINE__));


// if no xpath is given, just take the whole file
if ( (is_null($xpath)))
{
$newchild->append_child($tmpxml->root());
}
else
{
$xctx = $tmpxml->xpath_new_context();
$xnode = xpath_eval($xctx,$xpath);
foreach ($xnode->nodeset as $node)
{
$newchild->append_child($node);
}
}

}
else {
$MainXmlString = $this->xmldoc->dumpmem();
$string = preg_replace("/<\?xml.*\?>/","",$string);

$MainXmlString = preg_replace("/<".$this->xmlroot->{$this->tagname}."\/>/","<".$this->xmlroot->{$this->tagname}.">xmlroot->{$this->tagname}.">",$MainXmlString);
$MainXmlString = preg_replace("/<\/".$this->xmlroot->{$this->tagname}.">/",$string."xmlroot->{$this->tagname}.">",$MainXmlString);

$this->xmldoc = xmldoc($MainXmlString);
$this->xmlroot = $this->xmldoc->root();

}
}

/**
* sets the encoding for the db2xml transformation
* @param string $encoding_from encoding to transform from
* @param string $encoding_to encoding to transform to
* @access public
*/
function setEncoding ($encoding_from = "ISO-8859-1", $encoding_to ="UTF-8")
{
$this->encoding_from = $encoding_from;
$this->encoding_to = $encoding_to;
}
/**
* @param array $parentTables parent to child relation
* @access public
*/

function SetParentTables($parentTables)
{
foreach ($parentTables as $table => $parent)
{
$table_info["parent_table"][$table]=$parent;
}
$this->SetOptions(array("user_tableInfo"=>$table_info));
}


/**
* returns the content of the first match of the xpath expression
*
* @param string $expr xpath expression
* @return mixed content of the evaluated xpath expression
* @access public
*/

function getXpathValue ($expr)
{

$xpth = $this->xmldoc->xpath_new_context();
$xnode = xpath_eval($xpth,$expr);

if (isset ($xnode->nodeset[0]))
{
$firstnode = $xnode->nodeset[0];

$children = $firstnode->children();
$value = $children[0]->content;
return $value;
}

else
{
return Null;
}
}

/**
* get the values as an array from the childtags from the first match of the xpath expression
*
* @param string xpath expression
* @return array with key->value of subtags
* @access public
*/

function getXpathChildValues ($expr)
{
$xpth = $this->xmldoc->xpath_new_context();
$xnode = xpath_eval($xpth,$expr);

if (isset ($xnode->nodeset[0]))
{
foreach ($xnode->nodeset[0]->children() as $child)
{
$children = $child->children();
$value[$child->{$this->tagname}] = $children[0]->content;
}
return $value;
}
else
{
return Null;
}
}

}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/314311.htmlTechArticle{ if (is_array($value) ! $delete) { foreach ($value as $suboption = $subvalue) { $this-{$option}["$suboption"] = $subvalue; } } else { $this-$option = $value; } } } } } // these ar...


推荐阅读
  • 本文介绍了使用cacti监控mssql 2005运行资源情况的操作步骤,包括安装必要的工具和驱动,测试mssql的连接,配置监控脚本等。通过php连接mssql来获取SQL 2005性能计算器的值,实现对mssql的监控。详细的操作步骤和代码请参考附件。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 如何实现织梦DedeCms全站伪静态
    本文介绍了如何通过修改织梦DedeCms源代码来实现全站伪静态,以提高管理和SEO效果。全站伪静态可以避免重复URL的问题,同时通过使用mod_rewrite伪静态模块和.htaccess正则表达式,可以更好地适应搜索引擎的需求。文章还提到了一些相关的技术和工具,如Ubuntu、qt编程、tomcat端口、爬虫、php request根目录等。 ... [详细]
  • 本文介绍了lua语言中闭包的特性及其在模式匹配、日期处理、编译和模块化等方面的应用。lua中的闭包是严格遵循词法定界的第一类值,函数可以作为变量自由传递,也可以作为参数传递给其他函数。这些特性使得lua语言具有极大的灵活性,为程序开发带来了便利。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 本文讨论了Alink回归预测的不完善问题,指出目前主要针对Python做案例,对其他语言支持不足。同时介绍了pom.xml文件的基本结构和使用方法,以及Maven的相关知识。最后,对Alink回归预测的未来发展提出了期待。 ... [详细]
  • 本文介绍了在SpringBoot中集成thymeleaf前端模版的配置步骤,包括在application.properties配置文件中添加thymeleaf的配置信息,引入thymeleaf的jar包,以及创建PageController并添加index方法。 ... [详细]
  • Java验证码——kaptcha的使用配置及样式
    本文介绍了如何使用kaptcha库来实现Java验证码的配置和样式设置,包括pom.xml的依赖配置和web.xml中servlet的配置。 ... [详细]
  • 高质量SQL书写的30条建议
    本文提供了30条关于优化SQL的建议,包括避免使用select *,使用具体字段,以及使用limit 1等。这些建议是基于实际开发经验总结出来的,旨在帮助读者优化SQL查询。 ... [详细]
  • 1、概念解读1.1什么是链接?链接是一种在共享文件和访问它的用户的若干目录项之间建立联系的方法。Linux系统中有两种链接:硬链接(HardLink)和软链接(SoftLink), ... [详细]
  • php还能用多少年(php还行吗)
    导读:很多朋友问到关于php还能用多少年的相关问题,本文编程笔记就来为大家做个详细解答,供大家参考,希望对大家有所帮助!一起来看看吧!本文目录一览: ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 本文讨论了如何优化解决hdu 1003 java题目的动态规划方法,通过分析加法规则和最大和的性质,提出了一种优化的思路。具体方法是,当从1加到n为负时,即sum(1,n)sum(n,s),可以继续加法计算。同时,还考虑了两种特殊情况:都是负数的情况和有0的情况。最后,通过使用Scanner类来获取输入数据。 ... [详细]
  • PostgresX2 MPP部署试验
    2019独角兽企业重金招聘Python工程师标准MPP结构:129GTM节点,130coordinator、gtm_proxy、datanode& ... [详细]
  • 本文目录一览:1、\mysybase.dump对数据库正常使用有影响吗 ... [详细]
author-avatar
仔田
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有