Jump to content

preg_match question


Seb76
Go to solution Solved by 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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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