如何使用php eval()用垂直线(|)求解数学方程

So I have an algorithm creator where my users can create algorithms using variables from a list of possible variables. The algorithms they create need to be validated, so I substitute the variables with "1" just to check if they're valid and return a number without creating any errors. My problem is that I need it to be possible to create an algorithm like

(0.5*(1+7-|1-7|))

The issue with this is the vertical line (|) which is used to get the absolute value of the equation in it. When I send this equation to eval() it returns this error:

Parse error: syntax error, unexpected '|' in controller.php(425) : eval()'d code on line 1

Is there a math alternative to get the absolute value that I could use here or is there any way to escape this character so that it doesn't give an error but still does the equation correctly?

UPDATE ended up taking @AbraCadaver's advice and did

$string = preg_replace('/\|([\d.-]+)\|/', 'abs($1)', $string);