Humpty Posted March 8, 2007 Share Posted March 8, 2007 G'day Guys. I need to access a page (CGI) on a different server. I can do this fine with an include and that will display all the info I need on the screen. The problem I face is that I actually need to parse through that info. When i try assigning it to a variable... $dogggg = include ("$SpecialString"); ...the variable is always "1". $specialString is the URL Clearly what I am doing is wrong but if someone can please point me in the right direction for what I need to do in order to get that output into a variable so that I can parse it, do what I need to with that info and then display it. Thaks heaps -Humpty Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/ Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 curl is what you want. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202159 Share on other sites More sharing options...
trq Posted March 8, 2007 Share Posted March 8, 2007 This can be easily achieved with output buffering. $var contains the output of your include. <?php ob_start(); include 'urltoinclude'; $var = ob_get_clean(); // rest of code. ?> Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202161 Share on other sites More sharing options...
Humpty Posted March 8, 2007 Author Share Posted March 8, 2007 cURL: artacus; It seems to be a very full featured thing. I was after something far simpler though. ob_start(): thorpe; That is exactly what I was after. Thankyou very much for that. I would like to thank you both for this and really appreciate it, you have both given me two new things to look into for other future uses. Thanks. ...did I say thanks yet? -Humpty Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202172 Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 That will only work if he wants to display that page. Its not going to work if he wants to return it as a variable and parse thru it. $dogggg = include ("$SpecialString"); returns 1 meaning it succeeded. It's NOT the text from the page. If it's a page that you have control over (I doubt it), you can make it's contents read something like <?php $doggg = "...whatever..."; Otherwise use curl. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202173 Share on other sites More sharing options...
Humpty Posted March 8, 2007 Author Share Posted March 8, 2007 No, No this is good: ob_start(); include ("$SpecialString"); $var222 = ob_get_clean(); $var333 = strstr($var222, 'INVALID'); It gives me that ability to do what I need to do. When I say Parse I mean more than anything search through a string in most cases for a specific item or keyword. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202178 Share on other sites More sharing options...
trq Posted March 8, 2007 Share Posted March 8, 2007 Its not going to work if he wants to return it as a variable and parse thru it. Read my post. The output of the include is now stored in $var. Of course... an even easier option (which slipped my mind for some wierd reason) would be to simply use file_get_contents. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202179 Share on other sites More sharing options...
artacus Posted March 8, 2007 Share Posted March 8, 2007 The output of the include is now stored in $var. Yeah I missed the var assignment the first time thru. file_get_contents works for this huh? You are a genius. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202187 Share on other sites More sharing options...
Humpty Posted March 8, 2007 Author Share Posted March 8, 2007 does either have merrits over the other? (cURL is out of the picture now) Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202192 Share on other sites More sharing options...
trq Posted March 8, 2007 Share Posted March 8, 2007 I would think that using file_get_contents is cleaner, even if it just on your end. Performance wise I should'nt imagine there would be too much difference. Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202216 Share on other sites More sharing options...
Humpty Posted March 8, 2007 Author Share Posted March 8, 2007 Again Thank you to both of you Quote Link to comment https://forums.phpfreaks.com/topic/41701-solved-feed-included-url-into-a-variable/#findComment-202259 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.