Forum Moderators: coopster
$cookie = 'audio.0_backgroundimages._browserpatch.1';$my_pattern = '/.$/';
list($audio, $backgroundimages, $browserpatch) = split($my_pattern, $cookie);
echo $audio;
The desired match in this instance would be '0'.
- John
Your $cookie is 'audio.0_backgroundimages._browserpatch.1' and you want to do a split with the period as your delimiter, and you have three list variables, but you have 4 split instances. So yes as mentioned above you would need to escape the period (I personally like to bracket it, just in case you want more than one delimiter), so I would go:
list($audio, $backgroundimages, $browserpatch) = split('[.]',$cookie); So in your example:
$audio = 'audio'
$backgroundimages = '0_backgroundimages'
$browserpatch = '_browserpatch' Is that what you wanted to do? And is this a static format for your strings? Because you could just do a second list function afterwards on $backgroundimages:
list($int,$str) = split('_',$backgroundimages'); That would give you your 0
if (preg_match("/\.(.)/",$str,$match))
{
$result=$match[1];
}
Note that I'm not the best at regex though!
I reference the "sets" in a way like CSS...
property.value
property.value_property.value_property.value_property.value
There are more like a dozen properties and values stored in the cookie. I just shortened it to avoid being obnoxious on the thread by creating a horizontal scrollbar. ;)
All I need the regex to do is get the value of a property. In this instance that value simply is '0' (for the property audio). The goal of course is to echo $audio at the end of all things said and done and have it echo '0', or if you change the 0 in the cookie to 11 then echoing $audio would echo '11'.
I use the dots and underscores because they don't turn in to %20, %35, etc symbols (they're not considered entities I presume so what are they correctly referenced as?)
...any way the . I decided to use to "connect" visually (as this is PHP) for concatenate (not to actually connect them, just a symbolization of sorts). The underscore separates each set.
This also works though it seems somewhat repetitive? But it works! So I'm still interested in the proper regex so I guess this would go a ways to demonstrate the desired effects...
<?php
$cookie3 = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0';
$pieces = explode('_', $cookie3);
foreach($pieces as $val) {
$contents=explode('.', $val);
$$contents[0]=$contents[1];
}
echo '$audio = <b>'.$audio."</b><br />\n";
echo '$backgroundimages = <b>'.$backgroundimages."</b><br />\n";
echo '$browserpatch = <b>'.$browserpatch."</b><br />\n";
echo '$chatroom = <b>'.$chatroom."</b><br />\n";
echo '$connection = <b>'.$connection."</b><br />\n";
echo '$css3 = <b>'.$css3."</b><br />\n";
echo '$cursors = <b>'.$cursors."</b><br />\n";
?>
Any way I'm still interested in the regex which I haven't been able to figure out yet. If this method above however creates less of a load I'd happily use it instead however. Either way the more ways I can figure out how to do any one particular thing would hopefully help me figure out how to change things to make them more efficient later on.
- John
$cookie3 = 'audio.0_backgroundimages._browserpatch.1_chatroom.0_connection.0_css3.0_cursors.0';
$pieces = explode('_', $cookie3);
foreach($pieces as $value) {
list($cat,$val) = split('\.',$value);
echo "$cat = <b>$val</b><br />\n";
} That seems to work and use a little less code. Oh well best I could do from what I inferred you needed done.
-Doc