Advanced Search

Results 1 to 4 of 4

Thread: Change exploded string of property/values in to variable/values?

  1. #1
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Question Change exploded string of property/values in to variable/values?

    I have a string $cookie that contains properties and values separated by underscores. I can explode the string to get an array of the property and values and below echo them out...

    <?php
    $cookie = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0';
    $pieces = explode('_', $cookie);
    echo $pieces[0].'<br />';
    echo $pieces[1].'<br />';
    echo $pieces[2].'<br />';
    echo $pieces[3].'<br />';
    echo $pieces[4].'<br />';
    echo $pieces[5].'<br />';
    ?>
    That will echo out...
    audio.0
    backgroundimages.
    browserpatch.1
    chatroom.0
    connection.0
    css3.0
    cursors.0
    What I'd like to do is have PHP convert each $piece to a variable and the part after each period to be assigned as that new variable's value.

    So the last part above I'd like to essentially look or be in effect like the following...

    $audio = 0;
    $backgroundimages = ;
    $browserpatch = 1;
    $chatroom = 0;
    $connection = 0;
    $css3 = 0;
    $cursors = 0;
    Suggestions please?

    - John

  2. #2
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    Code:
    <?php
    $cookie = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0';
    $pieces = explode('_', $cookie);
    foreach($pieces as $val) {
    $contents=explode('.', $val);
    $$contents[0]=$contents[1]
    }
    echo $audio;
    echo $backgroundimages;
    echo $browserpatch;
    echo $chatroom;
    echo $connection;
    echo $css3;
    echo $cursors;
    ?>
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  3. The Following User Says Thank You to Master_script_maker For This Useful Post:

    JAB Creations (05-27-2008)

  4. #3
    Join Date
    Dec 2007
    Location
    Stranded in Sarasota Florida
    Posts
    75
    Thanks
    7
    Thanked 2 Times in 2 Posts

    Exclamation

    Excellent! It just does not get any more spot on then that! Thank you very much MSM! :cool

  5. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    you're welcome. always happy to help
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@ /\/\@|{
    There are 10 kinds of people in the world, those that understand binary and those that don't.

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
  •