S
S
sergeyviktorovich2021-08-03 17:44:08
PHP
sergeyviktorovich, 2021-08-03 17:44:08

How to strip the title from the string [:en]Black Brown[:de]Black Brown[:]?

There is this line: [:en]Black Brown[:de]Black Brown[:]. What is an easy way to get 1 title Black Brown?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Yakovlev, 2021-08-04
@sergeyviktorovich

$str = '[:en]Black Brown[:de]Black Brown[:]';
preg_match('/\[:en\]([^(\[:)]*)/', $str, $matches);
$str_en = $matches[1] ?? '';
echo $str_en;

J
John Didact, 2021-08-03
@JohnDidact

Replace all occurrences of \[.*?\] with an empty string

$str = '[:en]Black Brown[:de]Black Brown[:]';
$newStr = preg_replace('#\[:[a-z]*\]#is', '', $str);
var_dump($newStr); // 'Black BrownBlack Brown'
or, if readable words are needed, to a space, then remove whitespace characters from the beginning and end of the line (using the function trim())
Upd. I did not quite understand the task correctly ... What exactly should the result be? For what language? Or the first one that comes along?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question