DOM doc - 简单的查找元素 [英] DOM doc - simple find element

查看:102
本文介绍了DOM doc - 简单的查找元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好 -

我是PHP新手。我找到了FAQTS和php手册。我正在尝试这个

序列,但得到''没有找到zip字符串:''... PHP版本4.4.0


$ doc = new DomDocument ;

$ res = $ doc-> loadHTMLFile(&.;。/ aBasicSearchResult.html");

if($ res == true)

{

$ zip = $ doc-> getElementById(''zipRaw_id'') - > value;

if(0!= $ zip){

$ sql =''SELECT stuff ...''。 $ zip;


$ selected = mysql_select_db($ database,$ x_testC);

if(!$ selected){

$ res =''未连接:''。 mysql_error();

} else {

$ Result1 = mysql_query($ sql,$ x_testC);

if(!$ Result1){

$ res =''无查询:''。 mysql_error();

} else {

$ res = mysql_num_rows($ Result1);

}

}

}否则{

$ res ="找不到拉链字符串:" 。 $ zip;

}

}其他{

$ res =" loadHTMLFile()返回false" ;;

}


-----
Javascript中的
,这可以在doc


setTextContent(getElementById_s)中运行(''divZipCheckRes''),

getElementById_s(''zipRaw_id'')。value);


getElementById_s()是浏览器兼容性的封面功能..


-----

我刚试过这些变化


$ elem = $ doc- > getElementById(''zipRaw_id'');

// $ zip = $ elem-> getAttribute(''value'');

$ zip = $ elem-> innerText;


仍然没有什么

任何线索?提前谢谢


====

PHP版本4.4.0

配置命令''../configure'' ''--prefix = / opt / php / 4.4.0-mysql.4.1''

'' - disable-rpath'''' - enable-discard-path'''' --disable-debug''

'' - with-config-file-path = / opt / php / config''

'' - with-config -file-scan-dir = / opt / php / config / php.d''

'' - enable-magic-quotes'''' - disable-ipv6'''' - -with-openssl'''' - with-zlib''

'' - with-mime-magic'''' - with-mysql = / opt / mysql / 4.1.13a -1.gm''

'' - without-pgsql'''' - without-pear''''--enable-memory-limit''

'' - enable-static'''' - disable-shared'''' - enable-pcre-regex''

'' - with-exec-dir = / opt / php / current / bin'''' - with-gd''

'' - with-jpeg-dir = / usr / src / software / vanilla / jpeg-6b''

''--wit h-png-dir = / usr / src / software / vanilla / libpng-1.2.8''

'' - with-imap = / usr / src / software / vanilla / imap-2004b '''' - with-imap-ssl''

'' - enable-pcntl'''' - enable-mbstring''

Hi All-
I am new to PHP. I found FAQTS and the php manual. I am trying this
sequence, but getting ''no zip string found:''... PHP Version 4.4.0

$doc = new DomDocument;
$res = $doc->loadHTMLFile("./aBasicSearchResult.html");
if ( $res == true )
{
$zip = $doc->getElementById(''zipRaw_id'')->value;
if ( 0 != $zip ) {
$sql = ''SELECT stuff...'' . $zip;

$selected = mysql_select_db($database, $x_testC) ;
if ( !$selected ) {
$res = ''Not connected : '' . mysql_error();
} else {
$Result1 = mysql_query($sql, $x_testC) ;
if ( !$Result1 ) {
$res = ''No query : '' . mysql_error();
} else {
$res = mysql_num_rows($Result1);
}
}
} else {
$res = "no zip string found: " . $zip;
}
} else {
$res = "loadHTMLFile() returned false";
}

-----
in Javascript, this works in the doc

setTextContent( getElementById_s(''divZipCheckRes''),
getElementById_s(''zipRaw_id'').value );

getElementById_s() is a cover func for browser compatability..

-----
I just tried these variations

$elem = $doc->getElementById(''zipRaw_id'');
//$zip = $elem->getAttribute( ''value'' );
$zip = $elem->innerText;

still nothing
any clues?? thanks in advance

====
PHP Version 4.4.0
Configure Command ''../configure'' ''--prefix=/opt/php/4.4.0-mysql.4.1''
''--disable-rpath'' ''--enable-discard-path'' ''--disable-debug''
''--with-config-file-path=/opt/php/config''
''--with-config-file-scan-dir=/opt/php/config/php.d''
''--enable-magic-quotes'' ''--disable-ipv6'' ''--with-openssl'' ''--with-zlib''
''--with-mime-magic'' ''--with-mysql=/opt/mysql/4.1.13a-1.gm''
''--without-pgsql'' ''--without-pear'' ''--enable-memory-limit''
''--enable-static'' ''--disable-shared'' ''--enable-pcre-regex''
''--with-exec-dir=/opt/php/current/bin'' ''--with-gd''
''--with-jpeg-dir=/usr/src/software/vanilla/jpeg-6b''
''--with-png-dir=/usr/src/software/vanilla/libpng-1.2.8''
''--with-imap=/usr/src/software/vanilla/imap-2004b'' ''--with-imap-ssl''
''--enable-pcntl'' ''--enable-mbstring''

推荐答案

doc = new DomDocument;
doc = new DomDocument;


res =


doc-> loadHTMLFile(" ; ./ aBasicSearchResult.html");

if(
doc->loadHTMLFile("./aBasicSearchResult.html");
if (


这篇关于DOM doc - 简单的查找元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆