Hi, I am quite new to php but picking it up quite quickly, however I dont understand how a preg replace works. I am trying to count the number of columns selected but when I do the count I sometimes get +1 than what it should be.
e.g. I have in my array A,B,C the count would return 3 which is correct
but I have my data like this A,B,C, this adds 1 to the count because there is a comma on the end. I jus need to know how to do a preg_repace
here is a snippet from my code:
As you can see I have no idea how to do a preg_replace, so would any body be able to help me sort this and possibly explain in laymans terms how a preg_replace works?
Thanks in advance.
e.g. I have in my array A,B,C the count would return 3 which is correct
but I have my data like this A,B,C, this adds 1 to the count because there is a comma on the end. I jus need to know how to do a preg_repace
here is a snippet from my code:
Code:
// Store selected list of columns in session $_SESSION[$settingname]=$settings; // Write the session to SETTINGS / SETTINGSVALUES // ( default NAME='.userid' ie. '.coling' $settingname=".".$_SESSION['USERID']; writeSettings( array( 'name'=>$settingname, tabs=>'all' ) ); $sets=split(",",$settings); preg_replace("/,/", "{COMMA}", $settings); $num=count($sets); exit_error( "<center> $num Columns Saved successfully,<br><br> <input type='Button' class='submit' value='Close' onClick=\"javascript:window.close();\" > </center> " );
Thanks in advance.
Comment