Jump to content

preg_match question


Seb76

Recommended Posts

$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?

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.