Gorodetski Gorodetski - 6 months ago 52
PHP Question

Ignoring symbols in PHP

Suppose I have this code

<form method="POST">
<input type="text" name="expression">
<input type="submit" name="submitexpression">

$getexpression = $_POST['expression'];


if my input $getexpression value is: ((xyz)). how do i ignore the parenthesis so that when i use strlen it only gives a a value of 3 not 7.


I think preg_replace() is the better solution here as it will allow you to remove anything except alphabetical letters (as you requested in your comments):

$numChars = strlen(preg_replace("/[^A-Za-z]/", '', $getexpression));