PHP将字符串(1234)转换为整数

So in php $a = 1234; and $a = (1234); are both valid integers, 1234.

I have a situation with some third party code where I have $a = "(1234)"; (ie, a string)

The normal converting string to int don't work (because of the brackets)

<?php
$b = (int) $a; // 0
$b = intval($a); // 0

I could do something like

preg_match('/^\(([\d]+)\)$/', $a, $m);
$b = $m[1];

Just wondering if there there some clever way of converting $a back into an integer that I have missed?

The one more option can be

$str = "(1234)";

$int = (int) trim($str, '()');

This will make sure that if it has () that it makes it a negative number.

$a = '1234';

if (0 !== preg_match('/^\((\d+\))$/', $a, $matches)) {
    $b = (int)-$matches[1];
} else {
    $b = (int)$a;
}