PHP Regex for the following -
I have a variable that contains the following elements
$ value = '[" 1 "," 7.9 "," 12/01/2015 "] '; Now I want to create an array so that it will have the following values: -
$ array [0] = 7.9; $ Array [1] = 12/01/2015; I need PHP Reggae, which may be able to suspend the following elements in the above manner. I tried
$ ans = preg_match ('/ ^ [0-9,] + $ /', $ value); But it will not work to get help from Plz help array in the above way.
array [0] = 7.9; // zodiac array [1] = 12/01/2015; // date
your value "[" 1 "," 7.9 " , "12 \ / 2015 \"] " I think to be a Jason encoded array, I want you to use json_decode to get: > $ value = '["1", "7.9", "12/01/2015"]'; $ Array = json_decode (trim ($ value)); // Remove major and trailing spaces or / or as stated in the comments in $ array = json_decode ($ value); // Remove the first element ($ array now [$ 1, 7.9, 12/01/2015] $ result = array_slice ($ array, 1); var_dump ($ result); // array (7.9, 12/01/2015) < It is ok to assume double quotation marks around this value (1, 7.9 and date) because it stands, $ value is not valid string. < / P>
using regex like / [^ \ /., "] + [\. \ /] [^".,.] + / Also, in all, it should not be recommended here. However, for completeness: preg_match_all ('/ [^ \ /., "] + [[. $ / ^], $ Value = $ Matches [/ html>
Comments
Post a Comment