hchsk Posted May 2, 2009 Share Posted May 2, 2009 how can an external file's variables be "grabbed" without executing any of the printing/echoing or anything else Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/ Share on other sites More sharing options...
premiso Posted May 2, 2009 Share Posted May 2, 2009 ob_start and ob_end_clean Output buffering and by doing the end_clean it removes it the prints/echos from the buffer. Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-824377 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 it seems like that will also halt the return; is there a way to keep that? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825328 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 it seems like that will also halt the return; is there a way to keep that? What do you mean halt the return? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825342 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 it stops the return whatever; from being passed. even if didn't however, it wouldn't quite solve my problem, though i am interested to hear more about everything i can. i want a solution that stops the script from affecting ANYTHING outside of it, including database modifications, and overwriting files. all i want is a variable from inside of it Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825374 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Post your code. Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825379 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 ok, well i need this for several different scripts, but i'll give one example. heres a script i use to print a countdown to a date that changes, depending on the last post within a certain category on an RSS page: <?php //CONVERT SECONDS TO TIME function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if($time >= 31556926){ $value["years"] = floor($time/31556926); $time = ($time%31556926); } if($time >= 86400){ $value["days"] = floor($time/86400); $time = ($time%86400); } if($time >= 3600){ $value["hours"] = floor($time/3600); $time = ($time%3600); } if($time >= 60){ $value["minutes"] = floor($time/60); $time = ($time%60); } $value["seconds"] = floor($time); return (array) $value; }else{ return (bool) FALSE; } } /////////////////////////////////CALL FUNCTION: /////////////////////////////////inactive('team#'); function inactive($team) { $doc = new DomDocument; $doc->load('http://www.lowersouthlounge.com/updates.php'); $xpath = new DOMXPath($doc); $categories = $xpath->query("//item/category"); $pubDates = $xpath->query("//item/pubDate"); foreach ($pubDates as $pubDate) {$pub[] = $pubDate->nodeValue;} foreach ($categories as $categorie) {$category[] = $categorie->nodeValue;} $first = 1; for ($counter = 0; $counter <= count($category); $counter +=1){ if ((stristr($category[$counter], $team) != false) && ($first == 1)){ $lasteventtime = $pub[$counter]; $first = 0; $check = 1;} } //GET TIME NOW $ltime = time() + 3*60*60 ; $mytime = date('D, j M Y h:i:s',$ltime); //GET DIFFERENCE $inactive = (strtotime($lasteventtime)+259200) - strtotime($mytime); $inactive = Sec2Time($inactive); $inactive[display] = "$inactive[days]:$inactive[hours]:$inactive[minutes]"; if (intval($inactive[seconds]) < 0) {$inactive[display] = "<i>this team is inactive</i>";} if ($check != 1) {return 'error';} else {return $inactive;} } ?> now as you can see, it takes a parameter, $team, which is the category it searches for. now i need this script to serve two functions. i need to be able to include it in a page, and print the string $inactive[display] provided by the function when given different parameters at different points on the page. i also need it to supply the return value to another php script, but when it's included in the php script, it cant print out anything on it's own, i need to include the script, and when needed call the function with the tobedetermined parameter and get the return value. now that i'm typing and thinking about it more, i'm thinking about a solution that would just set a new variable $inactive[forscript], and repeatedly call the function with the different values before printing the variable $inactive[forscript], and that would contain what i needed. i'm not sure, but that might accomplish what i need. however, i would still like to find a way that i can do what i asked. /////i just remembered why the above solution does not work, look at my p.s. thanks again ps. i would like to use xml ajax to dynamically update every second the results of the functions i call and print within the website, this requires me to use a print or echo to display the result, but that will ruin my ability to access the function with different values via an include in the other script. but now that i'm thinking about THAT, that would still not work, because the echo for ajax.responseText would have to be echoed outside of the function, which ruins my ability to call the function with different parameters multiple times on a page Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825715 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 What's with all the   ? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825719 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 thats very odd, i'm not sure, theyre not in the script, when i posted it in the code tags the forum added those, here it is again outside of the tags: <?php //CONVERT SECONDS TO TIME function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if($time >= 31556926){ $value["years"] = floor($time/31556926); $time = ($time%31556926); } if($time >= 86400){ $value["days"] = floor($time/86400); $time = ($time%86400); } if($time >= 3600){ $value["hours"] = floor($time/3600); $time = ($time%3600); } if($time >= 60){ $value["minutes"] = floor($time/60); $time = ($time%60); } $value["seconds"] = floor($time); return (array) $value; }else{ return (bool) FALSE; } } /////////////////////////////////CALL FUNCTION: /////////////////////////////////inactive('team#'); function inactive($team) { $doc = new DomDocument; $doc->load('http://www.lowersouthlounge.com/updates.php'); $xpath = new DOMXPath($doc); $categories = $xpath->query("//item/category"); $pubDates = $xpath->query("//item/pubDate"); foreach ($pubDates as $pubDate) {$pub[] = $pubDate->nodeValue;} foreach ($categories as $categorie) {$category[] = $categorie->nodeValue;} $first = 1; for ($counter = 0; $counter <= count($category); $counter +=1){ if ((stristr($category[$counter], $team) != false) && ($first == 1)){ $lasteventtime = $pub[$counter]; $first = 0; $check = 1;} } //GET TIME NOW $ltime = time() + 3*60*60 ; $mytime = date('D, j M Y h:i:s',$ltime); //GET DIFFERENCE $inactive = (strtotime($lasteventtime)+259200) - strtotime($mytime); $inactive = Sec2Time($inactive); $inactive[display] = "$inactive[days]:$inactive[hours]:$inactive[minutes]"; if (intval($inactive[seconds]) < 0) {$inactive[display] = "<i>this team is inactive</i>";} if ($check != 1) {return 'error';} else {return $inactive;} } ?> Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825738 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 It should be $inactive['display']; Use quotes. Also, instead of checking if $first == 1, you can alternatively check $count == 0. And I don't know why you have $check = 1 either. Same with last time. I guess it's best if you start at the end of the array $category and stop there because that's what you're doing now - you're just storing the last entry anyways. Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825746 Share on other sites More sharing options...
premiso Posted May 4, 2009 Share Posted May 4, 2009 What's with all the ? http://www.phpfreaks.com/forums/index.php/topic,242385.0.html Somewhat explains it, but not really. Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825754 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 both good points, i'll change them, although i'm not sure why i need the quotes? i suppose that's just a standards issue. but any ideas on how to solve the larger problem? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825755 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 What's with all the ? http://www.phpfreaks.com/forums/index.php/topic,242385.0.html Somewhat explains it, but not really. I never had that problem when I edit my codes. o.O hchsk - Read up on associative arrays. If you just put display without quotes, it means it's a constant. And I doubt it is unless you defined it. Can you include in the code for the ob_start()? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825759 Share on other sites More sharing options...
hchsk Posted May 4, 2009 Author Share Posted May 4, 2009 ob_start hides the return value of the script no? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825779 Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 Well, what's the external variable you want to grab? I think we should have ask that before. Can I get an example? Quote Link to comment https://forums.phpfreaks.com/topic/156569-external-variables/#findComment-825786 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.