alonebfg Posted October 12, 2012 Posted October 12, 2012 (edited) I am in the process of orting out our google calander but i have a problem $url_to_check = "googlecalander.com/somecalandertest/basic"; class googlecalander_output { var $show_past_events = FALSE; var $sort_ascending = TRUE; var $orderby_by_start_date = TRUE; var $expand_single_events = TRUE; function check_url($url_to_check){ $tmp = str_replace("/basic","/full",$url_to_check); if(!strpos($tmp,'?')) $tmp = $this->append($tmp,'?'); else{ if(!(substr($tmp, -1) === '&')) $tmp = $this->append($tmp,'&'); } if($this->show_past_events) $tmp = $this->append($tmp,'futureevents=false&'); else $tmp = $this->append($tmp,'futureevents=true&'); if($this->sort_ascending) $tmp = $this->append($tmp,'sortorder=ascending&'); else $tmp = $this->append($tmp,'sortorder=descending&'); if($this->orderby_by_start_date) $tmp = $this->append($tmp,'orderby=starttime&'); else $tmp = $this->append($tmp,'orderby=lastmodified&'); if($this->expand_single_events) $tmp = $this->append($tmp,'singleevents=true&'); else $tmp = $this->append($tmp,'singleevents=false&'); return $tmp; } $feed = temp }?> echo $feed; it will eventually put on an internal web so that people can put in any google cal xml rss url and depending on setting will change the url and at the moment display it but eventually I will use the $feed to feed it to another programme as a correctly formated feed. at the moment nothing happens $feed is blank this is not my code but orignal code does not work either Edited October 12, 2012 by alonebfg
zag Posted October 12, 2012 Posted October 12, 2012 Sure you don't need http:// in the url? Also you should check to see if the url exists before processing it.
unixman_again Posted October 12, 2012 Posted October 12, 2012 $feed = temp temp is a constant and you haven't initialised it hence $feed will be blank. It most likely should be $feed = $tmp but YMMV as I haven't worked out what the code does. I've just spotted the obvious error.
shadowx Posted October 12, 2012 Posted October 12, 2012 $feed = temp temp is a constant and you haven't initialised it hence $feed will be blank. It most likely should be $feed = $tmp but YMMV as I haven't worked out what the code does. I've just spotted the obvious error. Agreed, it could be a deliberate thing but "temp" is never used except in that last line, so unless there is more code somewhere "temp" == NULL hence you'll get no output Also "echo $feed" is outside the PHP code (comes after "?>") You also don't seem to be calling the function "check_url()", the code defines in but doesn't call it, try replacing $feed = temp; With $feed = check_url($url_to_check); Then you are calling function and assigning it's returned value (Which is $tmp) to the variable $feed, if that makes sense?
alonebfg Posted October 12, 2012 Author Posted October 12, 2012 (edited) here is the orignal code have changed the $feed bit but it does not seem to return anything I dont know why I was given the code and only know the basics of php I cant seem to find ot why its not working changing $feed = $url_to_check; to $feed = check_url($url_to_check); the tells me Fatal error: Call to undefined function check_url() in C:\xampp\htdocs\test\new.php on line 38 insted of blank page $url_to_check = ('http://www.google.com/calendar/feeds/ford.plymouth.sch.uk_fcbr34ae6jag4pah8oogd7id50%40group.calendar.google.com/private-9b334582e4341761e0cc732328184757/basic'); // Create a new class that extends an existing class function init(){ $this->set_item_class('http://schemas.google.com/g/2005'); } class Gcal_edit { function check_url($url_to_check){ $tmp = str_replace("/basic","/full",$url_to_check); if(!strpos($tmp,'?')) $tmp = $this->append($tmp,'?'); else{ if(!(substr($tmp, -1) === '&')) $tmp = $this->append($tmp,'&'); } if($this->show_past_events) $tmp = $this->append($tmp,'futureevents=false&'); else $tmp = $this->append($tmp,'futureevents=true&'); if($this->sort_ascending) $tmp = $this->append($tmp,'sortorder=ascending&'); else $tmp = $this->append($tmp,'sortorder=descending&'); if($this->orderby_by_start_date) $tmp = $this->append($tmp,'orderby=starttime&'); else $tmp = $this->append($tmp,'orderby=lastmodified&'); if($this->expand_single_events) $tmp = $this->append($tmp,'singleevents=true&'); else $tmp = $this->append($tmp,'singleevents=false&'); return $tmp; } } ?> Super Duper News Scroller Edited October 12, 2012 by alonebfg
alonebfg Posted October 12, 2012 Author Posted October 12, 2012 ok now I am confused for I am not that clever at php can someone tell me why $tmp = str_replace("/basic","/full",$url); but if i call it as a function IE function check_url($url){ $tmp = str_replace("/basic","/full",$url); } it stops working ??
zag Posted October 12, 2012 Posted October 12, 2012 A function is something you call from somewhere else, it usually has some kind on input. In this case its the $URL
shadowx Posted October 12, 2012 Posted October 12, 2012 ok now I am confused for I am not that clever at php can someone tell me why $tmp = str_replace("/basic","/full",$url); but if i call it as a function IE function check_url($url){ $tmp = str_replace("/basic","/full",$url); } it stops working ?? I think that should work but within a function you always need to use "return $variable" A function kinda of works like function NameOfFunction($Variables, $used, $InFunction){ do; some; stuff_with($variables); return $WhateverYouWantToDisplay } In your code you are not actually returning the variable so you would need to modify it to be either: function check_url($url){ $tmp = str_replace("/basic","/full",$url); return $tmp; } //Then outside the function you can do... echo function_check_url($url); Or you can make the function do the echo statement too, such as; function check_url($url){ $tmp = str_replace("/basic","/full",$url); echo $tmp; } Note that in the second option you dont need to use RETURN, that's because the function already does the ECHO itself, so RETURNing the value of $tmp is pointless. For me personally I would always go with the first option, the reason being that if you have a function which automatically echos out the variable $tmp, if you want to do something else with that variable, let's say you cant to check it and then insert it into a database then you need to write the code from scratch. If you tried to re-use the check_url function every single time it would blurt out "$tmp" into the page for no reason. But if you DIDNT use echo WITHIN the function then you can safely reuse that function elsewhere and instead of doing echo $tmp; you can use insert_into_database($tmp); Does that make sense? TLDR; Use the first option, not the second
alonebfg Posted October 12, 2012 Author Posted October 12, 2012 Thank you sorted it I think my bad feel an idiot I was not calling the function correctly ie I used echo $tmp; when it should have been echo check_url($url) ok for now but might be back lol
shadowx Posted October 12, 2012 Posted October 12, 2012 Thank you sorted it I think my bad feel an idiot I was not calling the function correctly ie I used echo $tmp; when it should have been echo check_url($url) ok for now but might be back lol Everyone has to learn The amount of stupid mistakes I've made is ridiculous! My advice is just to code as much as possible, then you will lean as you go. Eventually you will be coding stuff for you to use in the office, here me and the NM made a nice little PHP helpdesk together which is really useful along with other random crap of course!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now