Jump to content

codeinphp

Members
  • Posts

    38
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by codeinphp

  1. Thanks again, I see adding the . just before = conecates the string. Had not thought of that, thank very much.
  2. Thanks for taking the time to look at this. In your example code won't the $cdata only contain the last value of $safe_item once the loop is finished? I was trying something like your example by the only way I could get each value of $safe_item into the $cdata was to include the $cdata in the loop, which of course creates a new instance of createDataSection with each loop.
  3. Not completely sure, will have to look over and see if possible. The xml being generated is basically a template that a component of Brightscript (for Roku) will read when loading. All elements of the generated xml would never change, only the addChannel and add Item info. The addChannel info is all generated thru a php script I have written that parses out xml info from multiple xml files and puts them together. I had been saving all the info into a json array file and have the Roku read the json array. The creators of Roku have developed a new component that allows developers create screens thru xml templates, one being the one I am working with. I will see if I can create xml nodes and see if this works. Have a feeling the Brightscript component is setup to read the template a certain way and may not recognize the information. Thanks for the idea.
  4. Is it possible to append to cdatasection within xml file using a loop without creating a new cdata section with each loop thru. The code starts out by creating the basics for xml then enters into a loop to go thru each element of an array, appending the cdata. $xml=new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $components = $xml->createElement("components"); $name=$xml->createAttribute("name"); $name->value = "customEPGGrid"; $extends=$xml->createAttribute("extends"); $extends->value = "EPGGrid"; $components->appendChild($name); $components->appendChild($extends); $script = $xml->createElement("script"); $type=$xml->createAttribute("type"); $type->value = "text/brightscript"; foreach ($items as $item){ //ENTER INTO LOOP $cdata=$xml->createCDATASection(<<<EOT function init() m.content = createObject("RoSGNode","ContentNode") m.top.setFocus(true) dateNow = CreateObject("roDateTime") dateNow = dateNow.asSeconds() - 2000 addChannel({$item['name']}) addItem({$item['name']}, dateNow) m.top.content = m.content m.top.translation = [50, 300] m.top.numRows = 5 m.top.duration = 10800 m.top.nowNextMode = false m.top.infoGridGap = 0 m.top.channelInfoColumnLabel = "HELLO" end function sub addChannel(channelText as string) m.channel = m.content.createChild("ContentNode") m.channel.TITLE = channelText m.channel.HDSMALLICONURL = "http://css.boshanka.co.uk/wp-content/uploads/2015/04/icon-logo-design-small.png" end sub sub addItem(progText as string, timeStart) For i=0 To 5 Step 1 program = m.channel.createChild("ContentNode") program.TITLE = progText + str(i) program.PLAYSTART = timeStart + (i * 2000) program.PLAYDURATION = "2000" End For end sub EOT ); } $script->appendChild($cdata); $script->appendChild($type); $components->appendChild($script); $xml->appendChild($components); $xml->save($filename2); When executed like this, I get a new createCDATASection with each pass thru the loop. Not really wanting this, but one createCDATASection with different value or $item['name'].
  5. Thanks, not knowing alot about php, this really helped.
  6. I need to create an xml file with php. Most of the xml is no problem, but part of it has cdata with other information. Following is how the output should look <?xml version="1.0" encoding="utf-8" ?> <component name="customEPGGrid" extends="EPGGrid" > <script type="text/brightscript" > <![CDATA[ function init() print "inside epg" m.content = createObject("RoSGNode","ContentNode") m.top.setFocus(true) dateNow = CreateObject("roDateTime") dateNow = dateNow.asSeconds() - 2000 addChannel("ABC") addItem("ABC Show ", dateNow) m.top.content = m.content m.top.translation = [50, 300] m.top.numRows = 5 m.top.duration = 10800 m.top.nowNextMode = false m.top.infoGridGap = 0 m.top.channelInfoColumnLabel = "Hello" end function ]]> </script> </component> $xml=new DOMDocument('1.0', 'UTF-8'); $xml->preserveWhiteSpace = false; $xml->formatOutput = true; $components = $xml->createElement("components"); $name=$xml->createAttribute("name"); $name->value = "customEPGGrid"; $extends=$xml->createAttribute("extends"); $extends->value = "EPGGrid"; $components->appendChild($name); $components->appendChild($extends); $script = $xml->createElement("script"); $type=$xml->createAttribute("type"); $type->value = "text/brightscript"; $cdata = $xml->createCDATASection("function init()"); $script->appendChild($cdata); $script->appendChild($type); $components->appendChild($script); $xml->appendChild($components); $xml->save($filename2); Here is the php code that creates the xml. I can create the cdata element and the Function Int(), but not sure how to get the rest. Any help in gettig the information in the function int() would be appreciated.
  7. Thank you both for the advice and direction. After restructure of the array into. I'm sure it can be cleaner but I don't know a lot about PHP, only what I have read or found on forums. 0 => array ( 'start' => '201601221400', ), 1 => array ( 'time' => '201601221400', 'name' => 'ABC', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', ), I was able to parse as needed with the following: $counter=0; //CONTROL foreach ($items as $key=>$value){ echo "NEW CONTROL ".$value['start']."<br>"; foreach ($items as $item=>$time){ if($time['time']==$value['start']){ if(empty($time['time'])){ }else{ $counter=$counter + 1; $match[]=array( 'time'=>$time['time'], 'title'=>$time['title'], 'desc'=>$time['desc'], ); if ($counter==5){break;} if ($counter==5){break;} } } } $counter=0; }
  8. Psycho, you are correct in that the array needed to be restructured. I have done this and have the script running as needed. Thanks for the advice but either I didn't communicate my idea well or it was was just not understood. In your solution you break if the count of the $foundvalues==5. This is no good, it will only break for the first array then the count will be more than five. The $foundvalues is never reset so it's count will always be more than 5, correct? I replaced checking the count of the array with a counter that increments by 1. When it reaches 5 it breaks and resets. This gives me exactly what is needed, the first 5 arrays of each array. Thanks again
  9. Thanks for the advice. Psycho, not sure what you mean as to the structure of the array, I thought it was pretty straight forward, one array with three element (time, title, desc). Not going to argue at all about it but I thought my logic kinda follows what you did, of course yours is better since it works. Thank you for you input. Mac_gyver, that's kinda what I wanted to do but I couldn't figure out how to move to next "new" time value in the loop, or get it to move. Thanks to both for the help.
  10. Trying to build an array from elements taken from another array, which I thought would be easy but not so much. My first step is to create a $control that will be used in a loop later on. I am then looping thru an array file comparing an element's value to the $control. If the same, for testing I am sending it to browser. In code below, $control is already created. The array file I am looping thru has the following structure: $items=array ( 0 => array ( 'time' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', ), 1 => array ( 'time' => '201601221400', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', ), 2 => array ( 'time' => '201601221400', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.', ), Note: The number of 'time' elements vary as tho how many have the same value. In the example I posted this particular time element has 3 of the same value, some have more some have less. I want to loop thru the array file, compare the $control to the 'time' value, if equal it will echo to browser. I want the loop to continue for either as long as the $control and 'time' are equal or 5 is reached. for($i=0; $i< count($control); $i++){ foreach ($items as $item){ while (($items['time']==$control[$i]) || ($r < 5 )){ if ($r > 5){ echo "OUT. . ."."<BR>"; $r=0; }else{ $r=$r+1; echo $control[$i]." ". $r."<br>"; } } } } When this is ran, I get the first 5 values of the first 'time' but then nothing, it's not continuing to the next $control. Can somebody point out my error(s)? Thanks.
  11. Attempting to put multiple arrays together but having difficulty. The array looks like following: $items=array ( 0 => array ( 'start' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', ), 1 => array ( 'start' => '201601221400', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', ), 2 => array ( 'start' => '201601221400', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.', ), 3 => array ( 'start' => '201601221400', 'title' => 'The Talk', 'desc' => 'Actor William H. Macy; guest co-host Jane Kaczmarek; chef David LeFevre makes ricotta cavatelli pasta with clams and herbed bread crumbs.', ), 17 => array ( 'start' => '201601221500', 'title' => 'General Hospital', 'desc' => 'Jason recovers an important memory; Lulu turns to her mother for advice; Sonny keeps a breakthrough to himself; Nikolas makes a move.', ), 18 => array ( 'start' => '201601221500', 'title' => 'The First 48', 'desc' => 'Two out-of-town brothers get involved in a drug deal gone wrong; forensic evidence must be used to piece together a deadly shooting when people refuse to talk.', ), 19 => array ( 'start' => '201601221500', 'title' => 'Top Gun', 'desc' => 'A hot-shot Navy jet pilot (Tom Cruise) tangles with MiGs and flirts with a civilian astrophysicist (Kelly McGillis).', ), The array continues but I have only pasted part of it. I want to combine arrays based on the start element retaining each title and desc for each array. I anticipate the final array to look like: $items=array ( 0 => array ( 'start' => '201601221400', 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', 'title' => 'Teen Titans Go!', 'desc' => 'Robin makes the other Titans sell their treasured mementos from past adventures.', ), array ( 'start' => '201601221500', 'title' => 'General Hospital', 'desc' => 'Jason recovers an important memory; Lulu turns to her mother for advice; Sonny keeps a breakthrough to himself; Nikolas makes a move.', 'title' => 'The First 48', 'desc' => 'Two out-of-town brothers get involved in a drug deal gone wrong; forensic evidence must be used to piece together a deadly shooting when people refuse to talk. 'title' => 'Top Gun', 'desc' => 'A hot-shot Navy jet pilot (Tom Cruise) tangles with MiGs and flirts with a civilian astrophysicist (Kelly McGillis).', ), When I try to put the array together I either end up with an array like the initial array at top of post or one like $items=array ( 0 => array ( 'start' => '201601221400', ), 1 => array ( 'title' => 'FABLife', 'desc' => 'Mark Cuban (``Shark Tank\'\'); top five must-haves; collectors try to guess the prices of celebrity memorabilia; creating a high-end playroom and eliminating toy clutter without breaking the bank.', ), 2 => array ( 'title' => 'The First 48', 'desc' => 'A young man is robbed and killed while meeting up with a girl he met earlier; a man is gunned down outside an annual football game.', ), The above would be ok except the title and desc are in separate arrays from the start. Is there a way to combine the start and each title/desc into single array based on start?
  12. Thanks to both responses. Seeing the example helps clarify the sequence needed.
  13. Attempting to get a value of an array that's actually inside several arrays, one being multidimensional I do believe. The array has the following structure: [catalog] => Array ( [0] => Array ( [attributes] => Array ( [book] => 20160122 ) [section] => Array ( [0] => Array ( [id] => F100 [title] => Across the Sea ) [1] => Array ( [id] => F101 [title] => Blue Water ) [2] => Array ( [id] => F102 [title] => Red Rove I have been able to get a return of the values back for each except for the id and title using the following: foreach($result as $items){ foreach($items['catalog'] as $a){ foreach($a['attributes'] as $b){ foreach($b['section'] as $c){ foreach($c['book'] as $d){ foreach($d['id'] as $e){ print_r($e); } } } } } I can't seem to get the value for the id or title. Any help appreciated.
  14. I am sure this can be done, but I don't know enough about PHP. I am posting all my code with hopes somebody can point me right direction. I am looping thru an xml, parsing a url where I have xml files stored, loading the xml, parsing out the start, title and desc into a control array. I then loop thru the start element comparing its value to the control, if the same it writes it to array along with title and desc. Finally I create one array of the start, title and desc, which will be saved to php array file. I am trying to group all titles (along with desc) by start. foreach ($items as $load){ $contents[]= simplexml_load_file($load['guide']); //LOAD XML EACH CHANNEL foreach ($contents as $content){ //BUILD CONTROL ARRAY $control=array( 'start'=>$content->programme['start'], 'title'=>$content->programme->title, 'desc'=>$content->programme->desc, ); } $start[]=$content->programme['start']; foreach($start as $base){ if($base==$control['start']){ //COMPARE TO CONTROL echo $base." ".$control['title']."<br>"; $start[]=$control['start']; $title[]=$control['title']; $desc[]=$control['title']; } foreach($start as $final){ $guide=array( 'start'=>$final['start'], 'title'=>$final['title'], 'desc'=>$final['desc'], ); } }
  15. I have some html being parsed where the particular tag and values show up two times in the html. I wish to ignore it in the first section but parse it in the next. The first instance occurs in a list. <ul> <li class="prog_1046598 clearfix"> <span class="prog_name">SHOW NAME</span> <span class="prog_info">SHOW INFOspan> </li> The second occurs within a class. Basically the only thing that is identical is the prog_name but my code still grabs this. <div class="prog_cols"> <span class="prog_name">SHOW1</span> <div class="prog_time">SHOW TIME</div> <div class="prog_desc">SHOW INFO.<br/> </div> My code is the following. Even though I am using the div class="col th" to parse thru, I still get the prog_name in the span class from the above section. Is there a way to keep this from happening? $cols=$xpath->query('//div[@class="col th"]'); $aclasses=$xpath->query('//a[@class="channel_sched_link"]'); $progname=$xpath->query('//span[@class="prog_name"]'); $progtime=$xpath->query('//div[@class="prog_time"]'); $progdesc=$xpath->query('//div[@class="prog_desc"]'); foreach ($cols as $col){ $xcid=$col->getElementsByTagName('a'); foreach($xcid as $cids){ $cid[]=$cids->getAttribute('data-channelid'); for($x=0; $x<count($cid); $x++){ foreach ($progname as $name){ $show[]=$name->nodeValue; } $scid[]=$cids->getAttribute('data-channelid'); } }
  16. I was able to get this to work foreach ($cols as $col){ $xcid=$col->getElementsByTagName('a'); foreach($xcid as $cids){ $cid[]=$cids->getAttribute('data-channelid'); for($x=0; $x<count($cid); $x++){ foreach ($progname as $name){ $show[]=$name->nodeValue; } $scid[]=$cids->getAttribute('data-channelid'); } }
  17. Clean up html <div class="col th"> <a class="channel_sched_link" href="javascript:void(0)" title="TITLE1" data-channelid="1"> <img src="/XXXXX" width="30" height="20" alt="AA" />AA </a> </div> <div class="prog_cols"> <div class="col ts ts_1 prog_1045493 ps_0" data-catid="" > <span class="name">SHOW1</span> <div class="time">August 5, 2015, 11:00 am - 1:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_2 prog_1045494 ps_1" data-catid="" > <span class="name">SHOW2</span> <div class="time">August 5, 2015, 1:00 pm - 2:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_1 prog_1045495 ps_3" data-catid="" > <span class="name">SHOW3</span> <div class="time">August 5, 2015, 2:00 pm - 4:00 pm</div> <div class="desc">Information here.<br/> </div> </div> :
  18. Trying to parse some html but having trouble getting it into "groups". I am able to parse the html below into single elements with the following code. The html shown is only one group of information being parsed and is grouped by based on the data-channelid. Following this group starts a new section with a different data-channelid followed by same classes just with different values and iformation. How can it be parsed to have a result groupled by the data-channelid? As I show below, I can get each individual item by can't seem to put them together like: CHANNEL="1" SHOW="SHOW1" TIME="WHATEVERTIME" DESC="BLABLA" CHANNEL="1" SHOW="SHOW2" TIME="WHATEVERTIME" DESC="BLABLA" CHANNEL="1" SHOW="SHOW3" TIME="WHATEVERTIME" DESC="BLABLA" then once all elements related to CHANNEL="1", parse the next group based on its channelid. foreach ($aclasses as $aclass){ $cid[]=$aclass->getAttribute('data-channelid'); } foreach ($progcols as $progcol){ foreach ($names as $name){ $show[]=$name->nodeValue; } foreach ($times as $time){ $ptime[]=$time->nodeValue; } foreach ($descs as $desc){ $pdesc[]=$desc->nodeValue; } } //PROGRAMCOLS for($i=0; $i<count($show); $i++){ echo "CHANNEL. . . . . ".$cid[$i]."<br>"; echo "SHOW. . . . . ".$show[$i]."<br>"; echo "TIME. . . . . ".$ptime[$i]."<br>"; echo "DESC. . . . . ".$pdesc[$i]."<br>"; } <div class="col th"> <a class="channel_sched_link" href="javascript:void(0)" title="TITLE1" data-channelid="1"> <img src="/XXXXX" width="30" height="20" alt="AA" />AA </a> </div> <div class="prog_cols"> <div class="col ts ts_1 prog_1045493 ps_0" data-catid="" > <span class="name">SHOW1</span> <div class="time">August 5, 2015, 11:00 am - 1:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_2 prog_1045494 ps_1" data-catid="" > <span class="name">SHOW2</span> <div class="time">August 5, 2015, 1:00 pm - 2:00 pm</div> <div class="desc">Information here.<br/> </div> </div> <div class="col ts ts_1 prog_1045495 ps_3" data-catid="" > <span class="name">SHOW3</span> <div class="time">August 5, 2015, 2:00 pm - 4:00 pm</div> <div class="desc">Information here.<br/> </div> </div> </div>
  19. This works foreach($items as $item){ $a=$item['cid]; }
  20. When this is executed I get error stating "Undefined variable: items " and "nvalid argument supplied for foreach()".
  21. I know this should be fairly simple but I have having a really hard time understanding. I can parse html using tags and elements but I am not able to parse an array. I am loading an array from a file with the structure shown: <?php error_reporting(0); $items = array( array( "name" => "A&E", "number" => "", "id"=>"I265.28459333.microsoft.com", "country" => "United States", "url" => "68952", "url2" => "playlist.m3u8?xs=", "url3" => "playlist.m3u8?xs=", "url4" => "", "stream" => "http://streams/A&E.m3u8", "image" => "http://image/generic.png", "Guide" => "http://GUIDE/AE.xml", "liveguide" => "http:///streamguideXML/A&E.xml", "cid" => "9" ), array( "name" => "ABC", "number" => "", "id"=>"0", "country" => "United States", "url" => "46476", "url2" => "playlist.m3u8?xs=", "url3" => "playlist.m3u8?xs=", "url4" => "playlist.m3u8?xs=", "stream" => "http://ABC.m3u8", "image" => "http://image/generic.png", "Guide" => "http://GUIDE/ABCHD.xml", "liveguide" => "http://streamguideXML/ABC.xml", "cid" => "14" ), ?> I load the file by using file_get_contents but from there I am kinda of lost. I seem to think it's the way the file is structured that is confusing me but not sure. I have tried: $file=file_get_contents("http://channel_list.php"); foreach($items as $item){ $a=$item->cid; } But this doesn't work at all. I know the $file is populate, I can var_dump and shows everything. I want to pick out different elements but mainly the cid. If I could get some guidance to that I can take it from there. Thanks for any help.
  22. Never mind, my mistake. I am getting info back. Once again thank you for taking your time to help me.
  23. What does your data.txt file look like? My result to browser is correct but nothing is saved to file.
  24. Thanks again. I will go thru your code and find my error. When I run your script I get a proper var_dump.
×
×
  • 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.