GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Quick php question (https://gfy.com/showthread.php?t=1028507)

thunder99 06-30-2011 02:58 AM

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?

V_RocKs 06-30-2011 03:39 AM

Without or without www.?

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

explode is your friend.

misterhhs 06-30-2011 03:52 AM

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

V_RocKs 06-30-2011 04:02 AM

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

Soteko 06-30-2011 04:27 AM

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;


Dido 06-30-2011 06:22 AM

Quote:

Originally Posted by thunder99 (Post 18249976)
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

thunder99 06-30-2011 07:07 AM

Quote:

Originally Posted by Soteko (Post 18250073)
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.

Kiopa_Matt 06-30-2011 07:18 AM

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.


All times are GMT -7. The time now is 04:56 AM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc