Page 2 of 2
Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 1:18 pm
by JAB Creations
There are no hard feelings...I just don't think I made it clear that the output absolutely has to be as plain as can be variables.
In effect I'm asking for copper dollars and you're giving me golden Euros...just I can't afford to deal with the currency exchange.
Any way I'll post the greater script soon. I'll start getting drowsy soon and if I don't get this working before I crash today then I won't have made enough progress to have made today worthwhile enough in contrast to the greater scale of things.
Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 1:18 pm
by VladSun
JAB Creations wrote:Any way I just don't think you're grasping that I need out to be as variables.
It's easy to do:
Code: Select all
$cookie = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0_dhtmleffects._dtd.1_ieccss.1_initialfocus.content_keyboardlayout.designer_mediatype._personality.0_powerkeys.0_sounds.0_theme.classic';
$pairs = split('[._]', $cookie);
for ($i = 0; $i < count($pairs) / 2; $i++)
${$pairs[$i*2]} = $pairs[$i*2 + 1];
Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 1:34 pm
by JAB Creations
Thank You!!!!!!!!!!!!!!!!!!!!!!!!!
The thing is while it's devastatingly minimal code and does
exactly what I want I'm staring at it having a little difficulty seeing how I might morph this in the future for similar situations. I really honestly try to do as much work on my own merit which is why I'm
still interested in the original regex filter.
Any way I do have a good question...if a value does not exist for the new variable how can we set it to '0' then?
Here is how I did it with the script I just recently posted (notice how 'backgroundimages' has no value but if you echo it out it will echo out as '0')...
Code: Select all
$cookie = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0';
$pieces = explode('_', $cookie);
foreach($pieces as $key=>$value)
{
$value = explode('.', $value);
if (empty($value[1])) {$value[1] = '0';}
else {
${$value[0]} = $value[1];
}
echo '$'.$value[0] .' = '. $value[1] ."\n";
}
Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 1:52 pm
by VladSun
// real offtopic
JAB, let me ask you something - why I should feel like helping you, when you've never used any of my suggestions. This thread, along with others related, are discussed by me from the very first one you'd posted. Let's have a look at
viewtopic.php?f=1&t=81833&hilit=cookie+serialize - it's where you started implementing the COOKIE based features (that is - you have no excuse for back-portability to your system). I gave you a lot of ideas, examples and ... nothing ... Now you are back with problems with your implementation and again I can't see where you've used any of the things I noted.
I've tried to help you again, but in every post you've sent I see that you are not using it at all.
I got a little tired... honestly...
It's good that you are trying to do it by your own, but you should learn to listen from time to time ...
Sorry, I had to say this ...
Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 1:58 pm
by JAB Creations
No I understand what you mean however I actually
do plan to use your last suggestion. I also just figured out a very possible solution, setting defaults if the cookie does not exist to begin with!
So I will be using your code suggestion pretty much as is. I'll probably have this all working in about an hour. I just have to make sure my site still works normally of course (locally of course too) once I have it working.
I
really think you'll like it.

Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 3:17 pm
by JAB Creations
Ok I have
everything working and today's long day was
not in vain!
I'm working on making a forum-tidy example.
For now here is an example of the old code (and I'll post the new version soon!)...
Code: Select all
class settings {
// class stuff defined here
}
if ($_GET['audio'] == "0") {$trueaudio = 0;}// if (!headers_sent()) {setcookie('audio','0',time()+2592000,'/');}}
else if ($_GET['audio'] == "1") {$trueaudio = 1;}// if (!headers_sent()) {setcookie('audio','1',time()+2592000,'/');}}
else if ($_GET['audio'] == "2") {$trueaudio = 2;}// if (!headers_sent()) {setcookie('audio','2',time()+2592000,'/');}}
else if (isset($_GET['audio'])) {$error = audio; $trueaudio = 0;}
else if ($_COOKIE['audio'] == "0") {$trueaudio = 0;}
else if ($_COOKIE['audio'] == "1") {$trueaudio = 1;}
else if ($_COOKIE['audio'] == "2") {$trueaudio = 2;}
else {$trueaudio = 0;}
if ($_GET['connection'] == "1") {$trueconnection = 1;}// if (!headers_sent()) {setcookie('connection','1',time()+2592000,'/');}}
else if ($_GET['connection'] == "2") {$trueconnection = 2;}// if (!headers_sent()) {setcookie('connection','2',time()+2592000,'/');}}
else if ($_GET['connection'] == "r") {$trueconnection = r;}// if (!headers_sent()) {setcookie('connection','r',time()-2592000,'/');}}
else if (isset($_GET['connection'])) {$error = connection; $trueconnection = 0;}
else if ($_COOKIE['connection'] == "1") {$trueconnection = 1;}// if (!headers_sent()) {setcookie('connection','1',time()+2592000,'/');}}
else if ($_COOKIE['connection'] == "2") {$trueconnection = 2;}// if (!headers_sent()) {setcookie('connection','2',time()+2592000,'/');}}
else {$trueconnection = 0;}
$settings = new settings();
$settings->set('audio',$audio);
$settings->set('connection',$connection);
...and keep in mind that those two large chunks of procedural programming...there are other large chunks for
EVERY preference that can be currently set on my website.
So any way I'll have the new version of my class file for you in a bit.

Re: PHP regex match *after* a period?
Posted: Sat May 24, 2008 3:49 pm
by JAB Creations
Ok I posted the new code for the wolves to chew on here...
viewtopic.php?f=50&t=83137
Let me know what you think please!
