English 中文(简体)
重复使用一项功能:如何履行这一职能——有一系列内容
原标题:Repetitive use of a function: how to perform this - with an array

首先,你们大家的季节感和幸福的新年! time!

The following code is a solution that returns the labels and values in a formatted array ready for input to mysql. Very nice;-)

<?php

$dom = new DOMDocument();
@$dom->loadHTMLFile( http://schulen.bildung-rp.de/gehezu/startseite/einzelanzeige.html?tx_wfqbe_pi1%5buid%5d=60119 );
$divElement = $dom->getElementById( wfqbeResults );

$innerHTML=   ;
$children = $divElement->childNodes;
foreach ($children as $child) {
$innerHTML = $child->ownerDocument->saveXML( $child );

$doc = new DOMDocument();
$doc->loadHTML($innerHTML);
//$divElementNew = $dom->getElementsByTagName( td );
$divElementNew = $dom->getElementsByTagname( td );

    /*** the array to return ***/
    $out = array();
    foreach ($divElementNew as $item)
    {
        /*** add node value to the out array ***/
        $out[] = $item->nodeValue;
    }

echo  <pre> ;
print_r($out);
echo  </pre> ;

} 

?>

这一法典的范围非常细微,它开展一项行动,即打算多次呼吁。 因此,在职能中加以总结是有道理的。 无论我们想要什么东西,我们都可以把它称作“多载”。 我试图用以下法典来做到这一点,但这并不适用。 我仍然无法确定在哪里把所建的——内部或之外——放在职能之内。

    <?php

    function multiload ($uid) {
    /*...*/
    //  $uid =  60119 ;

    $dom = new DOMDocument();

             $dom->loadHTMLFile( basic-url   . $uid);


         }

    multiload ( 60089 );
    multiload ( 60152 );
    multiload ( 60242 );
    /*...*/

    $divElement = $dom->getElementById( wfqbeResults );

    $innerHTML=   ;
    $children = $divElement->childNodes;
    foreach ($children as $child) {
    $innerHTML = $child->ownerDocument->saveXML( $child );

    $doc = new DOMDocument();
    $doc->loadHTML($innerHTML);
    //$divElementNew = $dom->getElementsByTagName( td );
    $divElementNew = $dom->getElementsByTagname( td );

        /*** the array to return ***/
        $out = array();
        foreach ($divElementNew as $item)
        {
            /*** add node value to the out array ***/
            $out[] = $item->nodeValue;
        }

    echo  <pre> ;

print_r($out);
echo  </pre> ;

}?>

说明

multicall( 60089 );
multicall( 60152 );
multicall( 60242 );
/*...*/

This is still repetitive, so we can put the numbers in an array - can ´t we! Then we can loop through the array.

$numbers = array ( 60089 ,  60152 ,  60242  /*...*/);
foreach ($numbers as $number) {
    doStuff($number);
}

But the question is - how to and where to put the loop!?

任何人都可以给我一个起点。

BTW - if i have to be more descriptive i am trying to explain more - just let me know... it is no problem to explain more

greetings Zero

www.un.org/Depts/DGACM/index_spanish.htm UPDATE: thaks to the grand help i now have made a grand step

<?php

    function multiload ($uid) {
    /*...*/
    //  $uid =  60119 ;

    $dom = new DOMDocument();

             $dom->loadHTMLFile( basic-url   . $uid);


         }

    multiload ( 60089 );
    multiload ( 60152 );
    multiload ( 60242 );
    /*...*/

    $divElement = $dom->getElementById( wfqbeResults );

    $innerHTML=   ;
    $children = $divElement->childNodes;
    foreach ($children as $child) {
    $innerHTML = $child->ownerDocument->saveXML( $child );

    $doc = new DOMDocument();
    $doc->loadHTML($innerHTML);
    //$divElementNew = $dom->getElementsByTagName( td );
    $divElementNew = $dom->getElementsByTagname( td );

        /*** the array to return ***/
        $out = array();
        foreach ($divElementNew as $item)
        {
            /*** add node value to the out array ***/
            $out[] = $item->nodeValue;
        }

    echo  <pre> ;

print_r($out);
echo  </pre> ;

}

$numbers = array ( 60089 ,  60152 ,  60242  /*...*/);
foreach ($numbers as $number) {
    multiload($number);
}

?>

i add the code a the end.... Now i have learned alot. By the way: I am very happy to be here!!! Greetings zero Now i try it out...

最佳回答

将这一职能从职能定义之外划出。 例如,在职能关闭<代码><>>>>后,您可直接将其定位:

<?php

function multiload ($uid) {
    // function code
}

$numbers = array ( 60089 ,  60152 ,  60242  /*...*/);
foreach ($numbers as $number) {
    multiload($number);
}

?>

从内部调动职能是有效的,但肯定不是你所希望的。 阅读http://en.wikipedia.org/wiki/Recursion” rel=“nofollow” 如果你自称自称职,你会重新发现发生的事情。 它可以是一种非常有用的技术,但在此并非如此。 但是,在阅读再次入侵之前,我建议你阅读一些关于写作职能的教学材料,例如

问题回答

暂无回答




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签