Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7943931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:24:49+00:00 2026-06-04T00:24:49+00:00

preg_match(/[\]/,”,$body); I use preg_match but I have this error here Compilation failed: missing terminating

  • 0
preg_match("/[\]/",'',$body);

I use preg_match but I have this error here

Compilation failed: missing terminating ] for character class at offset 3

What’s wrong here I can’t find it

$email_message = "Form details below.\n\n";

                    function clean_string($string) {
                        $bad = array("content-type","bcc:","to:","cc:","href");
                        return str_replace($bad,"",$string);
                    }

                    $email_message .= "Full Name: ".clean_string($_POST['full_name'])."\n";
                    $email_message .= "Email: ".clean_string($_POST['email'])."\n";
                    $email_message .= "Telephone number: ".clean_string($_POST['telephone'])."\n";
                    $email_message .= "Message: ".clean_string($_POST['comments'])."\n";


                    $mail             = new PHPMailer();
                    $body             = $email_message;
                    $body             = str_replace('\\', '', $body);

                    $mail->IsSMTP(); // telling the class to use SMTP
                    $mail->SMTPAuth   = true;                       // enable SMTP authentication
                    $mail->SMTPSecure = "ssl";                      // sets the prefix to the servier
                    $mail->Host       = "smtp.gmail.com";           // sets GMAIL as the SMTP server
                    $mail->Port       = 465;                        // set the SMTP port for the GMAIL server
                    $mail->Username   = "hanem@gmail.com";      // GMAIL username
                    $mail->Password   = "hinadk";       // GMAIL password

                    $mail->SetFrom('from-email@domain.com', 'First Last');

                    $mail->Subject    = "Imperia";

                    $mail->AltBody    = "To view the message, please use an HTML compatidble email viewer!"; // optional, comment out and test

                    $mail->MsgHTML($body);

                    $address = "hanem@gmail.com";
                    $mail->AddAddress($address, "To Name");

                    if(!$mail->Send()) {

                        echo "<font color='red'> Message error </font>". $mail->ErrorInfo;
                    } else {
                        echo "<font color='red'> Message sent </font>";
                    } 

there was eregi_replace(“[]”,”,$body);

but I had a another error for that reason i change it to preg_match

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:24:51+00:00Added an answer on June 4, 2026 at 12:24 am

    You’re escaping the last bracket but not the first. To match backslash, you can do:

    preg_match('/\\\\/', '', $body);
    

    From your edit, it appears you’re trying to remove backslashes from $body. In this case, you would need to use preg_replace. However, since your doing a simple search and replace, you’d be better off just using str_replace:

    str_replace('\\', '', $body);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this preg_match condition for matching positive, negative and decimal values /^[0-9,-\.]{1,50}$/ But
if (preg_match('#\b'.$rawword.'\b#i',$body)) { This code finds whole words, but if they are a hyphen
I currently have a preg_match to detect http:// and www. etc..... but I want
This is the preg_match i am trying to use to find specific text in
preg_match(/\w+/, $s, $matches); I have the PHP code above. I use it to match
if (preg_match ('/[^a-zA-Z0-9]/i', $getname)) { i use this preg_match pattern to check if a
I have tried: preg_match(/^[a-zA-Z0-9], $value) but im doing something wrong i guess.
I have this regex: preg_match(#^([0-9]+)$#, $post['telephone']) who allow only numbers (for a phone number
I want to preg_match [200932] this from a string. I tryied some pattern but
similar to this question: preg_match to extract mailto on anchor but I am trying

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.