Jump to content

Salacious

New Members
  • Posts

    2
  • Joined

  • Last visited

Salacious's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I was surfing the net looking for a quick and dirty way to take a table with 3 headers, 1 footer and its contents are create a comma delimited CSV file. what I came across is the following: preg_match('/<table(>| [^>]*>)(.*?)<\/table( |>)/is',$this->raw('./PayrollReportTable.report'),$b); $table = $b[2]; preg_match_all('/<tr(>| [^>]*>)(.*?)<\/tr( |>)/is',$table,$b); $rows = $b[2]; foreach ($rows as $row){ preg_match_all('/<td(>| [^>]*>)(.*?)<\/td( |>)/is',$row,$b); $out[] = strip_tags(implode(',',$b[2])); } $out = implode("\n", $out); var_dump($out); Its almost what I need, accept this solution ommits the headers (I have three remember) and the footer (only one). And I am not very good with rejex, so I was curious if some one here could me implement the missing pieces (header and footer). I would be ever so greatful. If you know of a better, cleaner, simpler, easier way please do share I am willing to try anything but over all what I have is pretty much what I want it just needs the headers and the footer. It should be noted that the actual table being processed here comes from: $this->raw('./PayrollReportTable.report')
  2. I apologize ahead of time if the code I post is too large. I did not see any posts regarding code length. I have the following array, that I created to be traversed and have specific parts passed into specific functions. $options = array( 'navigation' => array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', 'icon_url' => '', 'position' => '', 'sub_menues' => array( array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', ), array( 'page_title' => __('Aisis', 'aisis'), 'menu_title' => __('Aisis', 'aisis'), 'capabillity' => 'edit_themes', 'menu_slug' => 'aisis-core-options', 'function' => 'some_function', ), ) ), ); There are two main functions here that will be used add_menu_page() for the $options['navigation'] and add_submenu_page() for the $options['navigation']['submenues'] (yes I know there's a spelling mistake in submenues). The following code is a mess, how ever does almost what I need. Please bare with me, as It's no where near a finished product: foreach($options as $setting=>$option){ if($setting == 'navigation' && is_array($option)){ if(isset($option[$k])){ echo $option['page_title']; } foreach($option as $k=>$v){ if(is_array($v)){ foreach($v as $sub_menu){ foreach($sub_menu as $sk=>$sv){ if(isset($sub_menu[$sk])){ echo $sub_menu['menu_slug']; } } } } } } } Now what you'll see is something like echo $sub_menu['menu_slug'] - well, what if that key is not set? simple enough you say: if(isset($sub_menu['menu_slug'])){}else{} accept not, because this is where the functions come in handy, each key represents a value which is an argument for the function. no the function does not take an array of arguments, so, the question is: How do I take the array above and the code provided and do something like: foreach($option as $k=>$v){ if(is_array($v)){ foreach($v as $sub_menu){ foreach($sub_menu as $sk=>$sv){ if(isset($sub_menu[$sk])){ add_submenu_page($sub_menu['menu_slug'] /*...and so on....*/) } } } } } with out having to do a bunch of if is set, do this, else do that.I have to be able to pass in each individual key as a argument to the respected functions listed above, but I don't want to have to do a bunch of isset statements. I was thinking of doing something like in_array, or creating a walker that would look for the functions arguments. In case your wondering what the functions arguments are, look at the keys. they are the arguments, the values are the arguments values. So this is where I ask the community, what do I do? is there a simpler, cleaner way to achieve what I want?
×
×
  • 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.