开发者

Executing only the code of a page?

Hi guys consider I have a .php pa开发者_StackOverflowge that I need to include somewhere else.

page.php:

<?php 
 dosomecmd(); 
 doothercmd();
 //etc
?><html>pagehtml</html>

Is there a way to include this page but not printing the html inside? (I just need to execute those command)

I could do with ob

ob_start();
include('page.php');
ob_discard();

But i would prefer a faster way.

Thanks

Edit: i know i can sepearate html and php (and i already do) but that page.php is non else than a "static" cache I make, but sometimes I need to execute some command inside that cache instead to printing automatically it out

Edit2: of course i don't need everyime to not output the html (otherwise I could just delete all html) I need to return; only based on the results of my cmds up there

Thanks all i find a solution (add return;)


Would it be easier to have a common page with only the php that you need to share, and include it in both page.php and your other page?


you can try to seperate with $_SERVER['REQUEST_URI']

also I wouldn't recommend that


Try to separate the PHP logic at the start of your current script into another file, then include that into both of your scripts.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜