hackalive Posted June 5, 2010 Share Posted June 5, 2010 Hi guys so I have a PHP page with a function, now this function calls a HTML page and should return the contents to th exact spot where the cuntion is called, but it is returning it to the start of the document, any ideas how to fix this? (no iFrame suggestions please). $A = str_replace('<A>', require_once($dir.'/'.$file), $A); return $A; is the contents of the function, and this does call the right file, just how do I get it to return in a specific location? Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/ Share on other sites More sharing options...
ignace Posted June 5, 2010 Share Posted June 5, 2010 Functions like require_once(), include_once(), require(), and include() return 0 or 1 you need to return() it if you want to use it. $A = str_replace('<A>', 1, $A); is what you wrote (if the include was successful 0 otherwise). Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068135 Share on other sites More sharing options...
Tazerenix Posted June 5, 2010 Share Posted June 5, 2010 if you want to get the contents of the HTML page then use <?php $page = file_get_contents($dir . '/' . $file); $A = str_replace('<A>', $page, $A); return $A; ?> Is that what you wanted to do? if you also want to write back to the html page then use file_put_contents() Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068136 Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 but there is also PHP echoing on the HTML page so I dont think get_file_contents will work? any more ideas? Thanks ignace and Tazerenix Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068137 Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 Tazerenix I have just tried you suggestion and it does'nt handle the PHP Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068139 Share on other sites More sharing options...
Tazerenix Posted June 5, 2010 Share Posted June 5, 2010 mm, i didnt think it would parse PHP. It might parse it from absolute URL's (like calling http://google.com or something) so you might try that. Otherwise i'm not entirely sure how you would do it. Is the PHP inside that file 100% needed? EDIT: Hmm, i was looking at file_get_contents and i found this little cURL function. You might also like to try it: <?php function curl_get_file_contents($URL) { $c = curl_init(); curl_setopt($c, CURLOPT_RETURNTRANSFER, 1); curl_setopt($c, CURLOPT_URL, $URL); $contents = curl_exec($c); curl_close($c); if ($contents) return $contents; else return FALSE; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068140 Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 @ignace, yes it is returning a 1 @Tazerenix, yes that PHP needs to be there, I need to achive this somehow with the filr structure I have going So if anyone can think of a way to achive this let me know please, thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068141 Share on other sites More sharing options...
Tazerenix Posted June 5, 2010 Share Posted June 5, 2010 as i said you might want to try that curl function. Also try calling from an absolute address: <?php $page = file_get_contents('http://' . $_SERVER['HTTP_HOST'] . '/' . $dir . '/' . $file); ?> Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068143 Share on other sites More sharing options...
ignace Posted June 5, 2010 Share Posted June 5, 2010 ob_start(); include('filepath'); $content = ob_get_contents(); ob_end_clean(); Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068144 Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 okay what you suggested ignace works except..... now all the themeting etc is gone (it has replace <PL1> with the file but all the surrounding stuff for <PL1> which should stay is also gone. I have ob_start(); $A = str_replace('<A>', require_once($dir.'/'.$file), $A); $A = ob_get_contents(); return $A; Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068146 Share on other sites More sharing options...
Tazerenix Posted June 5, 2010 Share Posted June 5, 2010 <?php ob_start(); include('filepath'); $content = ob_get_contents(); ob_end_clean(); $A = str_replace('<A>', $content, $A); return $A; ?> Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068147 Share on other sites More sharing options...
hackalive Posted June 5, 2010 Author Share Posted June 5, 2010 Perfect, thanks so much ignace and Tazerenix, very very very much appreciated Quote Link to comment https://forums.phpfreaks.com/topic/203943-return-as-specific-location/#findComment-1068149 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.