dilbertone Posted December 25, 2010 Share Posted December 25, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/222628-how-to-combine-a-string-to-get-a-foreach-run-in-a-loop/ Share on other sites More sharing options...
revraz Posted December 25, 2010 Share Posted December 25, 2010 Can you load the numbers in an array? Quote Link to comment https://forums.phpfreaks.com/topic/222628-how-to-combine-a-string-to-get-a-foreach-run-in-a-loop/#findComment-1151332 Share on other sites More sharing options...
litebearer Posted December 25, 2010 Share Posted December 25, 2010 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 */ } Quote Link to comment https://forums.phpfreaks.com/topic/222628-how-to-combine-a-string-to-get-a-foreach-run-in-a-loop/#findComment-1151333 Share on other sites More sharing options...
dilbertone Posted December 25, 2010 Author Share Posted December 25, 2010 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>'; } Quote Link to comment https://forums.phpfreaks.com/topic/222628-how-to-combine-a-string-to-get-a-foreach-run-in-a-loop/#findComment-1151334 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.