Jump to content

codeinphp

Members
  • Content Count

    38
  • Joined

  • Last visited

  • Days Won

    1

codeinphp last won the day on May 31 2015

codeinphp had the most liked content!

Community Reputation

1 Neutral

About codeinphp

  • Rank
    Member
  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. Thank you I will try to parse it with that in mind.
×
×
  • 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.