Ok, since I never really got an hang on regex in PHP, it would be awesome if someone could link to a understandable article…
In this case i want to find a value in a string.
if example
$string = "blah blah blha lorem ipsum [get_this_value=10] more lorem ipsum";
i would like a function that returns “10”. it would be loverly if it was stored in array and that the function can retrieve many of them if there’s multiple of these i want them in an array.
$string = "blah blah blha lorem ipsum [get_this_value=10] more lorem ipsum [get_this_value=9] etc etc";
would return array(10, 9) and so on…
First you should learn about regular expressions. I can highly recommend this tutorial.
Then you can read up on some PHP specific regex issues in PHP’s documentation.
But to get you started, this would solve your problem:
Now
$matches[1]will be your desired array. Note that this does not depend on the specific stringget_this_value.For the purpose of you actually teaching yourself some regular expressions through the linked pages, I will not explain this regex in detail, but instead just tell you the concepts I have used. Unescaped square brackets
[...]mark a character class. In this case (due to the^) a negated one.\dis a built-in character class.+is a repetition quantifier. And parentheses(...)mark a capturing group.