Jump to content

How to combine a string to get a foreach & run in a loop


dilbertone

Recommended Posts

Hello dear community, good day!

 

first of all: Merry Christmas to all of you!!

 

 

How to combine / concatenate a *divided* string in order to use this combined / concatenated string in a loop where i run the

 

$dom = new DOMDocument();
@$dom->loadHTMLFile('<- path to the file-> =60119');

 

and the following.... numbers - Note: they replace the ending!!!

 

60299

64643

62958

63678

60419

60585

60749

60962

 

and so on. (

 

Question: How to combine the string (in fact the string is an URL) so that i am able to build the URLs automatically. And that i am able to run all that in a loop - eg with foreach [probably this is the right way to do that].

 

I hope that i was able to explain the question so that you understand it. If i have to be more descriptive - just let me know!

 

Many many thanks for a hint!

 

db1  ;)

 

Link to comment
Share on other sites

Perhaps like this?

$orig_string = "http://www.somesite.com?page=";
$number_array = array ("123", "43567", "9287","3323");
for($i=0; $i<$count($number_array); $i ++) {
$new_url = $orig_url . $number_array[$i];
/* do something with the new url */
}

Link to comment
Share on other sites

hello dear revraz, hello dear litebearer, good day

 

 

many many tanks to you both! Great to hear from you.

The idea with an array is convincing me! I am convinced! 

 

BTW: this uses the Dot-Operator, doesn ´t it!? One of two solutions for string- or Url-concetenation??

 

 

Perhaps like this?

$orig_string = "http://www.somesite.com?page=";
$number_array = array ("123", "43567", "9287","3323");
for($i=0; $i<$count($number_array); $i ++) {
$new_url = $orig_url . $number_array[$i];
/* do something with the new url */
}

 

many many thanks for the hint!!

 

btw; this is a absolute great forum - i love it!!  Many many thanks for the ideas and hints.

 

@ you both - you are very very supportive. GREAT To have you here!

 

Have a great season break and merry merry Christmas

 

greetings

Dilbertone!

 

 

Update: one last question: I integrate the loop solution with the array into my basic-script ....

 

<?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>';

} 

 

 

 

.......like so:

 

 

<?php

$dom = new DOMDocument();
$orig_string = "http://www.somesite.com?page=";

@$dom->loadHTMLFile {

$number_array = array ("123", "43567", "9287","3323");
for($i=0; $i<$count($number_array); $i ++) {

$new_url = $orig_url . $number_array[$i];

/* do something with the new url */
}

$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>';

} 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.