0

I have a sample code:

Acer phones (36)
Yezz phones (13)
Nokia phones (371)
Apple (1)

How to remove (digit) in this text I am using preg_replace("^\(d\)$", "", $name[$i]); // With $name[$i] is Acer phones (36), Yezz phones (13)...

1
  • 6
    \d+, not just d Commented Jun 7, 2012 at 7:51

2 Answers 2

2

Use this example, which is a small adaptation from your attempt:

$a = "Acer phones (36)";
$a = preg_replace("#\(\d+\)$#", "", $a);

the # are the pattern delimiters (required by PHP, you can pick almost any character you want)

the ^ has been removed, because you don't need to look from the exact start of the string, but $ has been kept because the (NN) is at the end of the string

"d" has been replaced by \d+ (remember to always escape special regex character, you forgot the escape in your example

Sign up to request clarification or add additional context in comments.

Comments

1

You're almost there:

preg_replace("/\(\d+?\)$/", "", $name[$i]);

Comments

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.