SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Myspace Gig Parser

    I have found this script that grabs the gig dates from a myspace page and displays them on an external page.

    It works fine. However, I'd like to remove the myspace styling of the table and add a class to it so I can style it externally.

    PHP Code:
    <?php
    $handle 
    fopen("http://www.myspace.com/capdown""rb");
    $contents '';
    while (!
    feof($handle)) {
      
    $contents .= fread($handle8192);
    }
    fclose($handle);
    $pieces explode("<table bordercolor=\"#6699cc\" cellspacing=\"0\" cellpadding=\"0\" width=\"440\" bgcolor=\"#6699cc\" border=\"0\">"$contents);

    $pieces2 explode("<table bordercolor=\"000000\" cellspacing=\"3\" cellpadding=\"0\" width=\"435\" align=\"center\" bgcolor=\"ffffff\" border=\"0\">"$pieces[1]);

    echo 
    "<table bordercolor=\"6699CC\" cellspacing=\"0\" cellpadding=\"0\" width=\"440\" bgcolor=\"6699CC\" border=\"0\">";
    echo 
    $pieces2[0];
    ?>
    Is this possible?

    http://www.gmtt.co.uk/details.php?file=14

  2. #2
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is it possible to remove a section from the string? The bit containing the style then "echo" this onto the page?

  3. #3
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes it is possible. What does the data actually look like? (I presume you are referring to the value of $pieces2[0]).
    Ian Anderson
    www.siteguru.co.uk

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    one note, they way you are using while(!feof($handle))

    if your fopen() call fails, you will send php into an endless while loop, which probably will make your webhost dislike you very quickly. this is because feof() will only return true when it has reached the end of a file, otherwise it will return false. thats how the infinate loop is caused, because it will never reach the end since it can never even start.


    you need to check and make sure that $handle is valid before you proceed with the while loop to avoid this.
    PHP Code:
    if ($handle) {
      while (!
    feof($handle)) {
        
    $contents .= fread($handle8192);
      } 


    you also may consider just using file_get_contents() if your php version supports it, its easier syntax and supposed to be faster.

  5. #5
    SitePoint Addict jamus's Avatar
    Join Date
    Jul 2004
    Location
    Devon, UK
    Posts
    301
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    wow

    you need to check and make sure that $handle is valid before you proceed with the while loop to avoid this.
    Thats fantastic, thanks!

    Also, my original request is no longer a problem.

    PHP Code:
    echo "<table class=\"whatever\"> 
    Works fine. I was trying to change the fread code. Dummy!

    Thanks again guys.


Bookmarks

Posting Permissions

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