function load_op($module, $filemap) { // Get the op $op = get_op(); // Check to see if the requested op exists in // the filemap array if (array_key_exists($op, $filemap)) { $filename = $filemap[$op]; } else { $filename = $filemap['default']; } // Build the fully qualified inclusion file $filename = "modules/{$module}/{$filename}"; // Return the filename to use return $filename; }
<?php /** * The code is my solution to the problem STRING SUBSTITUTION * on codeeval.com. * https://www.codeeval.com/public_sc/50/ */ $fh = fopen($argv[1], "r"); //$fh = fopen('sample.txt', "r"); while (true) { $test = fgets($fh); if (empty($test)) { exit(0); } $op = get_op($test); echo $op . PHP_EOL; } function get_op($str) { $arr_main = explode(';', $str); $str_main = $arr_main[0]; if (!trim($arr_main[1])) { return $str_main; } $arr_replacements = explode(',', $arr_main[1]); $arr_dict = array(); for ($i = 0; $i < count($arr_replacements); $i += 2) { $str_main = str_replace($arr_replacements[$i], '[' . $i . ']', $str_main); $arr_dict[$i] = $arr_replacements[$i + 1]; } foreach ($arr_dict as $key => $val) {
<div class="sidebar w320 fr"> <div id="localtime"></div> <div class="window mt25"> <img src="<?php echo bloginfo('template_url'); ?> /img/img1.png"/> </div> <?php if (is_single()) { // echo '暂时想不出什么模块!'; } elseif (get_op('cat') == 'show') { include 'inc/catalog.php'; } ?> <div class="news w350 mt25"> <h3 class="h3">热门推荐</h3> <ul> <?php $rand_posts = get_posts('numberposts=4&orderby=rand&post_status=publish'); foreach ($rand_posts as $post) { ?> <li> <a href="<?php the_permalink(); ?> " rel="bookmark" title="<?php the_title(); ?> " target="_blank"> <div class="news-img">
<?php get_header(); ?> <div id="content"> <div class="wrapper"> <div class="main fl"> <?php // Start the loop slide list if (get_op('slide') == 'show') { include 'inc/slide.php'; } // Start the loop sticky list if (get_op('sticky') == 'show') { include 'inc/sticky.php'; } ?> <div class="list w750 mt35"> <h3 class="h3">最新文章</h3> <div class="post-list fl mt15"> <?php // Start the loop post list get_template_part('content', get_post_format()); ?> </div> </div> </div> <?php get_sidebar(); ?>
<p>Link: <?php echo get_op('example_editor'); ?> </a></p>
?> </head> <body class="bg"> <div id="header" class="pt15"> <div class="wrapper"> <div class="nav fl"> <a href="javascript:;" class="nav-m"><i class="mo-menu"></i></a> <div class="logo fl"> <h1><a href="<?php bloginfo('url'); ?> " title="<?php bloginfo('nema'); ?> "><img src="<?php echo get_op('logo'); ?> "/></a></h1> </div> <ul class="menu fr"> <?php $menu = array('container' => false, 'items_wrap' => '%3$s', 'depth' => 0, 'theme_location' => 'nav'); echo strip_tags(wp_nav_menu($menu), '<li><a>'); ?> </ul> </div> <div class="tool fr"> <a href="javascript:;"><i class="mo-pencil"></i>投稿</a> <a class="sogin" href="<?php echo site_url('/wp-login.php'); ?>
echo get_op('slide_img3'); ?> "/></a> <a class="tit" href="<?php echo get_op('slide_url3'); ?> " target="_blank"><?php echo get_op('slide_tit3'); ?> </a> </li> <li> <a href="<?php echo get_op('slide_url4'); ?> " target="_blank"><img src="<?php echo get_op('slide_img4'); ?> "/></a> <a class="tit" href="<?php echo get_op('slide_url4'); ?> " target="_blank"><?php echo get_op('slide_tit4'); ?> </a> </li> </ul> </div> <div class="hd"><ul></ul></div> </div>