0

I am writing a class to handle some MySql functions.
For now, I want a regular expression pattern to detect operations.
Please see my code:

$a = "user_id <> 2";


$generalOperators = "/[<>|[<][\sA-Za-z0-9]|>|<|=]([\sA-Za-z0-9])/";
$op = "$1";
$asd = preg_replace($generalOperators, $op, $a);
echo $asd;

This will echo user_id 2 as output!
I am new to regular expressions.
Thanks in advance!

1
  • What exactly output you want , are you saying that this script will give output or need something else Commented Jan 29, 2013 at 8:49

2 Answers 2

1

you can also use str_replace() add more item you want to replace

$in_str = str_replace(array('<', '>', '&', '{', '}', '*', '/', '(', '[', ']' , '@', '!', ')', '&', '*', '#', '$', '%', '^', '|','?', '+', '=','"',','), array(''), $str);
Sign up to request clarification or add additional context in comments.

Comments

0
$a    = "user_id <> 2";
$res  = preg_replace("/[<>]/","",$a);

echo $res;

1 Comment

What all other character you need to replace ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.