Friday 15 August 2014

php - Show a pages code including require statements -



php - Show a pages code including require statements -

i trying display code of php file plain html. going except fact 'open up' <?php require 'main_content_bar.php'; ?> statements aswell.

so far have show_source($page); correctly working.

it prints:

<?php require 'main_content_bar.php'; ?> <!-- jumbotron --> <div class="jumbotron"> <h1>property</h1> <p class="lead">cras justo odio, dapibus ac facilisis in, egestas eget quam. fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit down amet.</p> </div> <div class="row"> <div class="col-md-12"> <h2>current properties</h2> </div> </div> <div class="footer"> <p><a href="source_code.php" target="_blank"> <img src="images/codebutton<?php echo $page_lower;?>.jpg" alt="<?php echo $page;?> source"> </img> </a></p> <p>&copy; robin b'stards retail 2014</p> </div> </body> </html>

however, 1 can see, contents of require statements not show. cannot life of me work out how this.

so end looking this:

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <script src="jquery-2.1.1.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css"> <!-- <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/css/bootstrapvalidator.min.css"/>--> <!-- <script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery.bootstrapvalidator/0.5.2/js/bootstrapvalidator.min.js"></script>--> <link href="justified-nav.css" rel="stylesheet"> <script> $(function(){ var url = window.location.href; var page = url.substr(url.lastindexof('/')+1); $('.nav a[href*="'+page+'"]').parent().addclass('active'); }); </script> </head> <body> <div class="container" style="width: 1263px"> <div class="masthead"> <h3 class="text-muted">ruthless real estate</h3> <ul class="nav nav-justified"> <li class="menu"><a href="property.php">property</a></li> <li class="menu"><a href="client.php">client</a></li> <li class="menu"><a href="type.php">type</a></li> <li class="menu"><a href="feature.php">feature</a></li> <li class="menu"><a href="multiple_properties.php">multiple properties</a></li> <li class="menu"><a href="property_features.php">property features</a></li> <li class="menu"><a href="images.php">images</a></li> </ul> </div> <!-- jumbotron --> <div class="jumbotron"> <h1>property</h1> <p class="lead">cras justo odio, dapibus ac facilisis in, egestas eget quam. fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit down amet.</p> </div> <div class="row"> <div class="col-md-12"> <h2>current properties</h2> </div> </div> <div class="footer"> <p><a href="source_code.php" target="_blank"> <img src="images/codebutton<?php echo $page_lower;?>.jpg" alt="<?php echo $page;?> source"> </img> </a></p> <p>&copy; robin b'stards retail 2014</p> </div> </body> </html>

note lack of require statements

you cannot show_source, "show code sources" of file.

you need create own function take filename in argument, have analyze source this:

replace require/include/require_once/include_once (what forget?) own content make function recursive (because main_content_bar.php can have other include within it) use highlight_string @ end of function.

edit search & replace, 1 way (there several) is utilize preg_match_all. part of code :

$new_content = file_get_contents('your-file.php'); $base_path = __dir__.'/'; // pattern find require, require_once, include, include_once functions // , grab arguments $pattern = "#<\?php (?:require|include(?:_once)?)\s*'(.*)'; \?>#u"; if (preg_match_all($pattern, $new_content, $matches)) { foreach($matches[0] $pattern_index => $full_pattern) { $file = $matches[1][$pattern_index]; $subcontent = file_get_contents($base_path.$matches[$pattern_index]); $new_content = str_replace($new_content, $full_pattern, $subcontent); } } highlight_string($new_content);

php html file

No comments:

Post a Comment