1

I have a string

$k="My name is Alice[1]";

What i want is to remove "[1]" from my string Using minimum steps,So that sentence will look like

$k="My name is Alice";

So antything that come inside [] should be removed.

3
  • 3
    What did you try so far? Commented Feb 7, 2014 at 9:20
  • nothing :-( not able to get it Commented Feb 7, 2014 at 9:22
  • codepad.viper-7.com/tW2cRE Commented Feb 7, 2014 at 9:25

3 Answers 3

1

Use this:

$text = preg_replace('/\[[0-9]+\]/','',$text);
Sign up to request clarification or add additional context in comments.

Comments

0

You can use preg_replace for this.

echo preg_replace('/\[[0-9]+\]/','',$str);

Comments

0

Do this:

$k="My name is Alice[1]";
$k = preg_replace('/\[[0-9]+\]/','',$k);

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.