Is this possible with PHP? If so, how?

Discussion in 'PHP' started by parker-94, Aug 31, 2010.

  1. #1
    Hello, I would like to start by pointing out my PHP skills are limited, so I ask that any help you offer is noob-friendly ;)

    On my forum, a PS3 forum, I would like to display their trophy cards automatically from PS3Trophycard.com

    Here's the URL's used by PS3Trophycard.com for reference:

    http://card.mmos.com/psn/profile/pa/r/parker-94/card.png

    I'm using phpBB to run my forum software, and have a custom field for determining their PSN ID, so usually replacing the "parker-94" part in the above URL with {postrow.POSTER_FROM}, which would automatically create the URLs.

    However, my issue is with the pa/r part of the URL. I need a code or script which reads the user's PSN ID, and takes the first two letters into one part, and then reads the third letter for the next bit, like so:

    http://card.mmos.com/psn/profile/[FIRST TWO LETTERS]/[THIRD LETTER]/[FULL PSN ID]/card.png

    I was wondering how I would go about doing so? Basically, I need PHP to read the first 2 letters of something, and then the third letter.

    Thanks in advance.
     
    parker-94, Aug 31, 2010 IP
  2. Gray Fox

    Gray Fox Well-Known Member

    Messages:
    196
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    130
    #2
    The fastest way is to treat your PSN ID string as an array and get your URL like this:

    
    $psnID = "parker-94";
    $url = "http://card.mmos.com/psn/profile/{$psnID[0]}{$psnID[1]}/{$psnID[0]}/{$psnID}/card.png";
    echo $url; // should output http://card.mmos.com/psn/profile/pa/p/parker-94/card.png
    
    PHP:
     
    Gray Fox, Aug 31, 2010 IP
  3. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I think Gray Fox misread the question slightly, should be:
    $psnID = "parker-94";
    $url = "http://card.mmos.com/psn/profile/{$psnID[0]}{$psnID[1]}/{$psnID[2]}/{$psnID}/card.png";
    echo $url; // should output http://card.mmos.com/psn/profile/pa/r/parker-94/card.png
    PHP:
    Here's an alternate way of doing it:
    $psnID = "parker-94";
    $url = 'http://card.mmos.com/psn/profile/' . substr($psnID, 0, 2) . '/' . substr($psnID, 2, 1) . '/' . $psnID . '/card.png';
    echo $url; // should output http://card.mmos.com/psn/profile/pa/r/parker-94/card.png
    PHP:
     
    exam, Aug 31, 2010 IP