boyjarv Posted June 9, 2020 Share Posted June 9, 2020 so far I have: $crawler->filter('li.date, dt > a, li.style')->each(function ($node) { $output = $node->text()."\n"; $array = explode("\n", $output); $data = array_chunk($array, 3); // print_r($data); foreach ($data as $row) { [$date, $title, $type] = array_pad($row, 3, null); // here you have your variables print 'Date: '.$date; print 'Title: '.$title; print 'Type: '.$type; } }); and this outputs: Quote Date: Saturday 13th Jun 2020Title: Type: Date: Alice in Chains UKTitle: Type: Date: Metal/ RockTitle: Type: Date: Monday 29th Jun 2020Title: Type: Date: Cage the ElephantTitle: Type: Date: Funk/ RockTitle: Type: Date: Friday 31st Jul 2020Title: Type: Date: The CureheadsTitle: Type: Date: Indie/ RockTitle: Type: Date: Thursday 20th Aug 2020Title: Type: Date: CreeperTitle: Type: Date: PunkTitle: Type: Date: Saturday 22nd Aug 2020Title: Type: Date: Fleetwood BacTitle: Type: Date: Pop/ RockTitle: Type: Date: Monday 31st Aug 2020Title: Type: Date: GZATitle: Type: Date: Hip HopTitle: Type: Date: Saturday 5th Sep 2020Title: Type: Date: Cock SparrerTitle: Type: Date: Only $date variable is set for each?! please help?? it should be: Date: Saturday 13th Jun 2020Title: Alice in Chains UKType: Metal/ Rock Date: Monday 29th Jun 2020Title: Cage the ElephantType: Funk/ Rock and so on.... Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/ Share on other sites More sharing options...
requinix Posted June 9, 2020 Share Posted June 9, 2020 You're parsing HTML as text. Don't do that. What's the actual HTML markup for the stuff you're reading? Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/#findComment-1578775 Share on other sites More sharing options...
boyjarv Posted June 9, 2020 Author Share Posted June 9, 2020 ok so I changed it to html() from text() $output now shows: Quote Saturday 13th Jun 2020 Alice in Chains UK Metal/ Rock Monday 29th Jun 2020 Cage the Elephant Funk/ Rock Friday 31st Jul 2020 The Cureheads Indie/ Rock Thursday 20th Aug 2020 Creeper Punk Saturday 22nd Aug 2020 Fleetwood Bac Pop/ Rock Monday 31st Aug 2020 GZA Hip Hop Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/#findComment-1578777 Share on other sites More sharing options...
requinix Posted June 9, 2020 Share Posted June 9, 2020 Actually I was hoping for the HTML markup. Not how your browser is displaying it to you. Do a View Source. Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/#findComment-1578778 Share on other sites More sharing options...
boyjarv Posted June 9, 2020 Author Share Posted June 9, 2020 I just want to set my list into 3 variables Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/#findComment-1578779 Share on other sites More sharing options...
requinix Posted June 9, 2020 Share Posted June 9, 2020 I know. Quote Link to comment https://forums.phpfreaks.com/topic/310910-trying-to-split-a-list-of-text-into-3-variables/#findComment-1578781 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.