Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Aug 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Begginer on PHP, conceptual help

    Hello, I'm trying to get into programming. I would like to know some basic concepts that I couldn't really find in youtube videos. How would I have a string and make it take out certain numbers and insert in into another string. For example.

    I paste this

    http://steamcommunity.com/profiles/76561197997953878/
    http://steamcommunity.com/profiles/76561197993826205/
    http://steamcommunity.com/profiles/76561198014217816/

    and turn it into

    add//profile//76561197997953878/
    add//profile//76561197993826205/
    add//profile//76561198014217816/

    I would really appriciate some help on this.

  2. #2
    Supreme Master coder!
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    10,055
    Thanks
    10
    Thanked 1,156 Times in 1,147 Posts
    You explode it (separate by delimiter character) and rebuild it.

    This is a 'longer' way to do it, but easy to follow ...
    Example:
    PHP Code:
    <?php

    // your original string
    $string="http://steamcommunity.com/profiles/76561197997953878/";

    // explode the string into array 'parts', as the string gets separated by '/' (delimiter) ...
    $parts=explode("/",$string);

    // you are looking for the long number, which is $parts[4];
    // $parts[0] is "http:"
    // $parts[1] is nothing
    // $parts[2] is "steamcommunity.com"
    // $parts[3] is "profiles"
    // $parts[4] is "76561197997953878"

    // so now build a new string ...

    $string="add//profile//".$parts[4]."/";

    echo 
    "Here is your string: ".$string;

    // ---------------------------------------------------
    // a shorter way to do the same thing.

    // your original string
    $string="http://steamcommunity.com/profiles/76561197997953878/";
    list(
    $http$null$domain$profile$id) = explode("/"$string);
    $string="add//profile//".$id."/";
    echo 
    "Here is your string: ".$string;


    ?>
    You may want to see this:
    http://www.tizag.com/phpT/


    .
    Last edited by mlseim; 08-03-2013 at 10:08 PM.


 

Tags for this Thread

Posting Permissions

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