Seb76 Posted May 18, 2018 Share Posted May 18, 2018 $rows[0][2]->val = preg_match("/\b[0-9]{6,6}-[0-9]{4,4}\b/", $rows[0][2]->val) $rows[0][2]->val = preg_replace("/\b[0-9]{6,6}-[0-9]{4,4}\b/", "Match", $rows[0][2]->val); Hi there. First question on the forum :-) I have a working code that uses the preg_replace but I would like to use the preg_match as to simply output a Match/No match I experimented with (I don't know why the code block goes on top) but I don't get any result. From what I understand I should get a 1 or 0. I probably do something wrong? Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 18, 2018 Share Posted May 18, 2018 What makes you think you should get back a 1 or 0? The manual says you will get back the updated string. Quote Link to comment Share on other sites More sharing options...
requinix Posted May 18, 2018 Share Posted May 18, 2018 If you want literally "Match" or "No match" then you want preg_match because that will tell you whether the regex matched. Should be obvious when it's phrased that way, right? Since it returns a number for how many times it matched then you'll want to turn that number into your string using whatever your favorite method of doing an if/then/else would be. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted May 18, 2018 Share Posted May 18, 2018 My bad. Requinex made me re-examine the OP question and I see now that I looked at the examples and assumed they were in time sequence. Mis-applied my knowledge (or lack of!) to the question. Sorry for not being a help... Quote Link to comment Share on other sites More sharing options...
Solution Seb76 Posted May 21, 2018 Author Solution Share Posted May 21, 2018 It's ok, I found the reason why it didn't do anything. So silly... I forgot the semi colon at the end... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.