+ Post New Thread
Results 1 to 10 of 10
Coding Thread, php problem in Coding and Web Development; I am in the process of orting out our google calander but i have a problem PHP Code: <?php $url_to_check  ...
  1. #1
    alonebfg's Avatar
    Join Date
    Aug 2006
    Location
    south west some of the time
    Posts
    834
    Thank Post
    12
    Thanked 34 Times in 21 Posts
    Blog Entries
    5
    Rep Power
    24

    php problem

    I am in the process of orting out our google calander but i have a problem
    PHP Code:
    <?php
    $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
    Last edited by alonebfg; 12th October 2012 at 09:10 AM.

  2. #2
    zag
    zag is offline
    zag's Avatar
    Join Date
    Mar 2007
    Posts
    3,829
    Thank Post
    918
    Thanked 422 Times in 355 Posts
    Blog Entries
    12
    Rep Power
    88
    Sure you don't need http:// in the url?

    Also you should check to see if the url exists before processing it.

  3. #3

    unixman_again's Avatar
    Join Date
    Nov 2011
    Posts
    756
    Thank Post
    30
    Thanked 151 Times in 114 Posts
    Rep Power
    137
    $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.

  4. #4

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14
    Quote Originally Posted by unixman_again View Post
    $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?

  5. #5
    alonebfg's Avatar
    Join Date
    Aug 2006
    Location
    south west some of the time
    Posts
    834
    Thank Post
    12
    Thanked 34 Times in 21 Posts
    Blog Entries
    5
    Rep Power
    24
    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
    PHP Code:
    <?php

    $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;
        }
        }

    ?>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8" />
    <title>Super Duper News Scroller</title>
    </head>

    <body>

    <div id="container">
            <?php echo $tmp?>
            
        
    </div>


    </body>
    </html>
    Last edited by alonebfg; 12th October 2012 at 11:30 AM.

  6. #6
    alonebfg's Avatar
    Join Date
    Aug 2006
    Location
    south west some of the time
    Posts
    834
    Thank Post
    12
    Thanked 34 Times in 21 Posts
    Blog Entries
    5
    Rep Power
    24
    ok now I am confused for I am not that clever at php can someone tell me why
    PHP Code:
    $tmp str_replace("/basic","/full",$url); 
    but if i call it as a function IE
    PHP Code:
    function check_url($url){
    $tmp str_replace("/basic","/full",$url);

    it stops working ??

  7. #7
    zag
    zag is offline
    zag's Avatar
    Join Date
    Mar 2007
    Posts
    3,829
    Thank Post
    918
    Thanked 422 Times in 355 Posts
    Blog Entries
    12
    Rep Power
    88
    A function is something you call from somewhere else, it usually has some kind on input. In this case its the $URL

  8. #8

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14
    Quote Originally Posted by alonebfg View Post
    ok now I am confused for I am not that clever at php can someone tell me why
    PHP Code:
    $tmp str_replace("/basic","/full",$url); 
    but if i call it as a function IE
    PHP Code:
    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

  9. #9
    alonebfg's Avatar
    Join Date
    Aug 2006
    Location
    south west some of the time
    Posts
    834
    Thank Post
    12
    Thanked 34 Times in 21 Posts
    Blog Entries
    5
    Rep Power
    24
    Thank you sorted it I think my bad feel an idiot I was not calling the function correctly ie I used
    PHP Code:
      echo $tmp
    when it should have been
    PHP Code:
    echo check_url($url
    ok for now but might be back lol

  10. #10

    Join Date
    Mar 2010
    Location
    shadowx@AllEvil:/
    Posts
    222
    Thank Post
    12
    Thanked 28 Times in 25 Posts
    Rep Power
    14
    Quote Originally Posted by alonebfg View Post
    Thank you sorted it I think my bad feel an idiot I was not calling the function correctly ie I used
    PHP Code:
      echo $tmp
    when it should have been
    PHP Code:
    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!

SHARE:
+ Post New Thread

Similar Threads

  1. PHP problems after server reboot
    By powert in forum Windows Server 2000/2003
    Replies: 14
    Last Post: 30th July 2012, 04:09 PM
  2. Moodle / PHP problem
    By BarryWAaMC in forum Virtual Learning Platforms
    Replies: 11
    Last Post: 18th March 2010, 01:17 AM
  3. PHP problem in win2k3 64bit
    By gianboy in forum Windows Server 2000/2003
    Replies: 6
    Last Post: 3rd August 2009, 02:46 AM
  4. php problems
    By freakyleaks in forum Coding
    Replies: 5
    Last Post: 23rd July 2008, 07:28 PM
  5. CMS - PHP problems
    By wesleyw in forum How do you do....it?
    Replies: 6
    Last Post: 12th July 2007, 09:22 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •