Quick php question

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thunder99
    Confirmed User
    • Nov 2003
    • 503

    #1

    Quick php question

    I know there's an easy way of doing this, but I'm having a brain freeze.

    I want to extract the domain name from this array value

    a:1:{s:10:"formfield1";s:17:"www.domain.com";}

    Anybody know how?
    yeah, yeah
  • V_RocKs
    Damn Right I Kiss Ass!
    • Nov 2003
    • 32449

    #2
    Without or without www.?

    Without loading it as JSON shit or whatever that format is...

    explode is your friend.

    Comment

    • misterhhs
      Confirmed User
      • Oct 2005
      • 165

      #3
      In my opinion this isn't even correct JSON.
      Php has some JSON-functions, these will be the easiest way.

      Comment

      • V_RocKs
        Damn Right I Kiss Ass!
        • Nov 2003
        • 32449

        #4
        This is fucked with by wordpress I am assuming. It has it's own API to pull it back out.

        But if it all is in the same format.. just explode it and move on

        Comment

        • Soteko
          Registered User
          • Aug 2002
          • 37

          #5
          Code:
          	
          
          $sString = 'a:1:{s:10:"formfield1";s:17:"www.domain.com";}';
          	
          $sTemp = explode(":", $sString);
          $iLastIndex = count($sTemp)-1;
          	
          $sDomain = str_replace( array('"', ';', '}'), "", $sTemp[$iLastIndex]);
          echo $sDomain;

          Comment

          • Dido
            Confirmed User
            • Sep 2006
            • 217

            #6
            Originally posted by thunder99
            I know there's an easy way of doing this, but I'm having a brain freeze.

            I want to extract the domain name from this array value

            a:1:{s:10:"formfield1";s:17:"www.domain.com";}

            Anybody know how?
            This is the way a serialized() array looks like in PHP.
            So I guess you could just unserialize() it and then extract $foo['formfield'], which should yield 'www.domain.com'...

            [edit]
            After actually checking if it would work, I noticed your original isn't formatted properly... the second part claims it's going to contain a string of 17 characters when it's only a 14 character one... so this exact example won't work, but the original of 'www.domain.com' would probably work just fine :P
            Last edited by Dido; 06-30-2011, 05:27 AM.
            Dido

            ADAMO Advertising - Your ULTIMATE traffic partner!

            If you need traffic or have traffic, we'd love to help you make the best out of it!

            ICQ:24209500 - Skype:diederikvanschaik

            Comment

            • thunder99
              Confirmed User
              • Nov 2003
              • 503

              #7
              Originally posted by Soteko
              Code:
              	
              
              $sString = 'a:1:{s:10:"formfield1";s:17:"www.domain.com";}';
              	
              $sTemp = explode(":", $sString);
              $iLastIndex = count($sTemp)-1;
              	
              $sDomain = str_replace( array('"', ';', '}'), "", $sTemp[$iLastIndex]);
              echo $sDomain;
              I ending up using something similar to this, thanks for the pointers Guys.
              yeah, yeah

              Comment

              • Kiopa_Matt
                Confirmed User
                • Oct 2007
                • 1448

                #8
                Above is wrong. Here:

                Code:
                $sString = 'a:1:{s:10:"formfield1";s:17:"www.domain.com";}';
                
                $vars = unserialize($sString);
                $domain = $vars['formfield1'];
                EDIT: Sorry, dido got it. Guess I should read the whole thread before replying.
                Last edited by Kiopa_Matt; 06-30-2011, 06:20 AM.
                xMarkPro -- Ultimate Blog Network Management
                Streamline your marketing operations. Centralize management of domains, pages, Wordpress blogs, sponsors, link codes, media items, sales and traffic statistics, plus more!

                Comment

                Working...