Gorodetski Gorodetski - 2 months ago 8
PHP Question

Ignoring symbols in PHP

Suppose I have this code

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

<?php
if(isset($_POST['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

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));