Question

I'm working on my PHP that I'm using simple_html_dom to find the list of elements that I'm looking for before I could splitting the contents into separate.

Here is the output:

<?xml version='1.0' encoding='UTF-8' ?>
<tv generator-info-name="www.mysite.com/test">
<p id='channels'>101 ABC FAMILY</p>
<p id='channels'>102 CBS</p>
<p id='channels'>103 CNN USA</p>
<p id='channels'>105 ESPN USA</p>
<p id='channels'>106 Fox News</p>
<p id='channels'>107 Animal Planet</p>

I want to split the contents into two different variables as the one is for the numbers and the other one is for the channels.

I want to split the numbers like this:

101
102
103
105
106
107

And I want to split the channels:

ABC FAMILY
CBS
CNN USA
ESPN USA
Fox News
Animal Planet

Here is the PHP

<?php
ini_set('max_execution_time', 300);
$errmsg_arr = array();
$errflag = false;
$link;
include ('simple_html_dom.php');
$xml = "<?xml version='1.0' encoding='UTF-8' ?>";
$xml = '<tv generator-info-name="www.mysite.com/test">';
$base1 = "http://www.mysite.com/get-listing.php";
$html = file_get_html($base1);      

foreach($html->find('p[id=channels]') as $element)
{
   echo $xml;
   echo $element;
}
?>

Can you tell me how I can split the contents I want to allow me to use two different variables as the one is for the numbers and the other one is for the channels?

Was it helpful?

Solution

foreach($html->find('p[id=channels]') as $element)
{
    $channelstr = $element->innertext;
    preg_match('/(\d+) (.*)/', $channelstr, $matches);
    echo $matches[1];
    echo $matches[2];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top