A
A
Andrey Sergeevich2018-09-17 17:37:54
PHP
Andrey Sergeevich, 2018-09-17 17:37:54

For goods, the article of the form XXXX 6653 needs to be converted to 6653 XXXX, can I somehow correct it not manually?

There is a site on phpshop, for goods the article of the form XXXX 6653 needs to be converted to 6653 XXXX, that is, swap numbers with letters, how can it be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Dart, 2018-09-17
@drew_nya

$res = implode(' ', array_reverse(explode(' ', 'XXXX 6653')));
print_r($res); // 6653 XXXX

D
Dmitry, 2018-09-17
@slo_nik

Good afternoon.
Try starting with the following:

$str = "XXXX 6653";
$pattern = "#(\w+)\s(\d+)#";
$replacement = "$2 $1";
echo preg_replace($pattern, $replacement, $str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question