Processing method for special characters in Eregi_replace () _ Regular expressions

Source: Internet
Author: User
I'm not familiar with the regular expressions of PHP.
When you use the Eregi_replace () function, you find that a string with () cannot be replaced, read the manual or muddle through
Like what
Add DIN 1693 (pt.2)-1997 Bold
Use
$str = ' din 1693 (pt.2)-1997 '
Eregi_replace ($str, "<strong>". $str. " </strong> ", $STR);
Finally, because the string contains parentheses, it cannot be processed
Now I know it's wrong, but I don't know what the right way to write it.
That warrior can teach me how to deal with this problem? And also
If you use lowercase letters to query
Use this function to replace the original uppercase letters to lowercase, do not know how to keep the original writing (uppercase or lowercase)
I see Google as such.

?
$str = ' din 1693 (pt.2)-1997 ';
echo Preg_replace ("/(". Preg_quote ($STR). ") /"," <strong>\\1</strong> ", $str);
?>
Escape
Quotemeta
Preg_quote

If the Ereg function group uses Quotemeta
If the Preg function group uses preg_quote
echo Preg_replace ("/(". Preg_quote ($STR). ") /"," <strong>\\1</strong> ", $str);
\\1 is a reference to the found part, which preserves the original case.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.