Gorodetski Gorodetski - 1 year ago 96
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.

Answer Source

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));
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download