Hi, I have a regular expression that I want to use to replace in a text but I haven´t figured out how to.
Using preg_replace I mange to replace it with some random text but I need to first work with the match and based on it the replacement text changes, I read the php.net manual and used preg_match and preg_match_all trying to store the matches in a variable but when I try to use the variable is null, can someone give me an idea
preg_replace($regex, "changed_text", $text);//this is working so my regular expression does work
this is the target text, in red the text that never changes, in green the text that is case sensitive
{|plugin|fbcomm|fr_FR|350|}
and this is how I am trying to store the matches to further work with them, it is either not working for me or have not really understood how to use the variable where the matches are stored, I tried both match and match_all
function change_text($matches[0]){
//do something to $matches[0]
}
//I also tried
function change_text($matches[0][0]){
//do something to $matches[0][0]
}
well, as I mentioned I am sure the regular expression works I tested it and I am able to replace it with some other text, what I am not able to do is use $matches to work with them and then replace it
And as I mentioned using the page I linked to you can easily see what is returned by preg_match and preg_match_all. Of course, you can do the same adding some var_dump statements in your code.
As far as your “use $matches” is concerned, who know why it doesn’t work. You didn’t show us what you are trying to do with it.
The page that you provided me does work, thank you and I will try to provide the necessary information on my next post, however I did mention that my regular expression works, I don’t know what was the reason $matches was not working but after waking up this morning and turning the computer back on the script worked just fine