M
M
Mikhail2021-09-27 15:58:35
PHP
Mikhail, 2021-09-27 15:58:35

How to get data in this form from text using PHP?

The text contains the following characters in square brackets: [id618892552|Victoria Tran]

you need to get them separately id: id618892552
and names, for example: Victoria Tran

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2021-09-27
@Mishaermolaev

preg_match_all('~\[(.+?)\|(.+?)\]~', $str, $matches);

S
Slava Rozhnev, 2021-09-27
@rozhnev

Another option:

$str = '[id618892552|Victoria Tran]';

list($id, $name) = explode('|', trim($str, ']['));

run php code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question