Clean text with preg_replace and regex in php

Hi experts,

I would like to clean a variable (text) from everything which is between [ and ].

Example:
$text = 'this is my [14] test text. there could be come [words] but I dont know where [123dsf]. thank you';
$description = preg_replace('??????', '', $text);
echo $description;

Open in new window


the end result should be:
this is my test text. there could be come but I dont know where . thank you

Basically delete all parts with [] and everything between the open [ and close ].

Thank you in advance
Oliver2000Asked:
Who is Participating?
 
Dan CraciunIT ConsultantCommented:
$description = preg_replace('/ \[.*?\]/', '', $text);

Open in new window

HTH,
Dan
0
 
Oliver2000Author Commented:
Easy and fast... Thank you for your help. This works perfect and I was also be able to adapt this for another problem :)
0
 
Dan CraciunIT ConsultantCommented:
You're welcome.

Glad I could help!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.