Jump to content

qamargrt

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Everything posted by qamargrt

  1. Hello, I want to get text from html tag. The html code is read which means I cannot add the additional coding just I need to get the text from a specific html tag and use it in php to compare. Any Idea how to do that?
  2. Thank you very much excellent description Now I understand the working. Cheers
  3. THANK YOU VERY MUCHHHHH it works. To be honest I as a newbie I have the right to ask how is it working? Although it looks simple but its better to ask to clear the confusion. I recently started working on PHP feeling it very confusing but hope to get better with the passage of time. Thanks again. Below is the working code. $abs = array(); function sortOverall($a, $b) { return $b->overallpoints - $a->overallpoints; } foreach ($teams as $team=>$value) { $abs[$team] = $value; } echo '<pre>'; uasort($abs, 'sortOverall'); print_r($abs);
  4. I am sorry I forgot to add overall points in parameter but still did not work Here is the code now $teams = new SimpleXMLElement('C:\\teams.xml',NULL,true); $abs = array(); function sksort(&$array, $subkey="id", $sort_ascending=false) { if (count($array)) $temp_array[key($array)] = array_shift($array); foreach($array as $key => $val){ $offset = 0; $found = false; foreach($temp_array as $tmp_key => $tmp_val) { if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { $temp_array = array_merge( (array)array_slice($temp_array,0,$offset), array($key => $val), array_slice($temp_array,$offset) ); $found = true; } $offset++; } if(!$found) $temp_array = array_merge($temp_array, array($key => $val)); } if ($sort_ascending) $array = array_reverse($temp_array); else $array = $temp_array; } foreach ($teams as $team) { $abs[] = $team; } echo '<pre>'; sksort($abs,'overallpoints'); print_r($abs); and here is the output : Array ( [0] => SimpleXMLElement Object ( [played] => 6 [won] => 3 [drawn] => 0 [lost] => 3 [overallpoints] => 9 ) [1] => SimpleXMLElement Object ( [played] => 3 [won] => 1 [drawn] => 0 [lost] => 2 [overallpoints] => 3 ) [2] => SimpleXMLElement Object ( [played] => 2 [won] => 1 [drawn] => 0 [lost] => 1 [overallpoints] => 3 ) [3] => SimpleXMLElement Object ( [played] => 1 [won] => 1 [drawn] => 0 [lost] => 0 [overallpoints] => 3 ) [4] => SimpleXMLElement Object ( [played] => 1 [won] => 0 [drawn] => 0 [lost] => 1 [overallpoints] => 0 ) [5] => SimpleXMLElement Object ( [played] => 1 [won] => 0 [drawn] => 0 [lost] => 1 [overallpoints] => 0 ) [6] => SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) [7] => SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) [8] => SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) [9] => SimpleXMLElement Object ( [played] => 2 [won] => 2 [drawn] => 0 [lost] => 0 [overallpoints] => 6 ) )
  5. I did use the commented one. It tested it with comment and with out comment but the result was same. Also If I use the code below you posted it gives warnings and doesnot effect at all. One more thing suppose if it sort the array with this code how the output would be because I need to sort according to overallpoints? Have a look at the XML below <?xml version="1.0" encoding="UTF-8" standalone="no"?> <teams> <dantooinedestroyers><played>6</played><won>3</won><drawn>0</drawn><lost>3</lost><overallpoints>9</overallpoints></dantooinedestroyers> <waylandwarriors><played>3</played><won>1</won><drawn>0</drawn><lost>2</lost><overallpoints>3</overallpoints></waylandwarriors><coruscantcrusaders><played>2</played><won>1</won><drawn>0</drawn><lost>1</lost><overallpoints>3</overallpoints></coruscantcrusaders><tatooinetraverllers><played>1</played><won>1</won><drawn>0</drawn><lost>0</lost><overallpoints>3</overallpoints></tatooinetraverllers><romulasrejects><played>1</played><won>0</won><drawn>0</drawn><lost>1</lost><overallpoints>0</overallpoints></romulasrejects><tottenhamskaro><played>1</played><won>0</won><drawn>0</drawn><lost>1</lost><overallpoints>0</overallpoints></tottenhamskaro><dynamonewearth><played>0</played><won>0</won><drawn>0</drawn><lost>0</lost><overallpoints>0</overallpoints></dynamonewearth><dagobahdragons><played>0</played><won>0</won><drawn>0</drawn><lost>0</lost><overallpoints>0</overallpoints></dagobahdragons><rurapenthemassive><played>0</played><won>0</won><drawn>0</drawn><lost>0</lost><overallpoints>0</overallpoints></rurapenthemassive><cardassiaprimewanderers><played>2</played><won>2</won><drawn>0</drawn><lost>0</lost><overallpoints>6</overallpoints></cardassiaprimewanderers></teams>
  6. Thank you for your response but it did not work with that function. I am using the code below to sort and print xml doc. //SimpleXML Element $teams = new SimpleXMLElement('C:\\teams.xml',NULL,true); $abs = array(); function sksort(&$array, $subkey="id", $sort_ascending=false) { if (count($array)) $temp_array[key($array)] = array_shift($array); foreach($array as $key => $val){ $offset = 0; $found = false; foreach($temp_array as $tmp_key => $tmp_val) { if(!$found and strtolower($val[$subkey]) > strtolower($tmp_val[$subkey])) { $temp_array = array_merge( (array)array_slice($temp_array,0,$offset), array($key => $val), array_slice($temp_array,$offset) ); $found = true; } $offset++; } if(!$found) $temp_array = array_merge($temp_array, array($key => $val)); } if ($sort_ascending) $array = array_reverse($temp_array); else $array = $temp_array; } // echo '<pre>'; // print_r($teams); foreach ($teams as $team) { $abs[] = $team; } echo '<pre>'; //sksort($abs); print_r($abs);
  7. I have the following php array structure and couldnot able to sort it according to the overall points. My code is reading an xml file using simplexml. Any help would be appreciated. Array ( [0] => SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) [1] => SimpleXMLElement Object ( [played] => 6 [won] => 3 [drawn] => 0 [lost] => 3 [overallpoints] => 9 ) [2] => SimpleXMLElement Object ( [played] => 3 [won] => 1 [drawn] => 0 [lost] => 2 [overallpoints] => 3 ) [3] => SimpleXMLElement Object ( [played] => 0 [won] => 0 [drawn] => 0 [lost] => 0 [overallpoints] => 0 ) [4] => SimpleXMLElement Object ( [played] => 2 [won] => 1 [drawn] => 0 [lost] => 1 [overallpoints] => 3 ) }
×
×
  • 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.