user3522738 user3522738 - 3 months ago 11x
PHP Question

php explode to split and combine reverse string

text left - text right

How to swap right to left using php? str pos is not so good because the pattern is not always fix. It could be
more left text here - right

The result that I want should look like
text right - text left

tried explode() but it isn't always single character at the left or right side.


Simply can use explode(). Example here

$str = "text left - text right";
$exp = explode('-', $str);
$newStr = trim($exp[1]) . ' - ' . trim($exp[0]);
echo $newStr;