Jump to content


Photo

preg_match question


Best Answer Seb76, Yesterday, 07:52 AM

It's ok, I found the reason why it didn't do anything. So silly... I forgot the semi colon at the end...  :tease-01:

Go to the full post


  • Please log in to reply
4 replies to this topic

#1 Seb76

Seb76
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 18 May 2018 - 12:53 PM

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

 

 

 



#2 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,194 posts
  • LocationVoorheesville NY

Posted 18 May 2018 - 01:30 PM

What makes you think you should get back a 1 or 0? The manual says you will get back the updated string.
JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#3 requinix

requinix
  • Administrators
  • Impoverished Administrator
  • 9,874 posts
  • LocationWA

Posted 18 May 2018 - 01:49 PM

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.
"Basically, I think the general rule of thumb is: if someone really wants the blood that's inside of your body, and they're like a vampire, or a dracula, or some sort of man-squito, then that's probably okay. A dracula and a man-squito are made for removing things like blood and swords from inside your body. That's basically fine. If something wants to get at your blood and they're, say, some kind of murdersaurus, or maybe a really big frog, that's where the problems start to arise. A really big frog is not made for removing blood, and your blood knows this, which is why it is so vehement about wanting to stay in your body instead of coming out. Unfortunately this will not deter a really big frog because a really big frog is full of things like prizes, and value, and quite a lot of hatred, and it would really rather like to replace any and all of those things with your blood, and basically by any means possible." --slumbermancer

#4 ginerjm

ginerjm
  • Members
  • PipPipPip
  • Handball player
  • 4,194 posts
  • LocationVoorheesville NY

Posted 18 May 2018 - 10:04 PM

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...
JG
PS - If you're posting here you should be using:
        error_reporting(E_ALL);
        ini_set('display_errors', '1');

at the top of ALL php code while you develop it!

#5 Seb76

Seb76
  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted Yesterday, 07:52 AM   Best Answer

It's ok, I found the reason why it didn't do anything. So silly... I forgot the semi colon at the end...  :tease-01:






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users