[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details

to handle result of mb_strpos function in php

Asked by eparampa in PHP Scripting Language

Tags: php, mb_strpos, string position

We are validating input characters in our php pages. Following is the code we have written to accomplish this. Since our input boxes should accept special characters like ÀÁetc., we have used mb_strpos function. But the problem is, if the function could not find a string's position (this meant, the character is invalid), it returns empty string. The application is treating the empty string as "0"(zero) and allows invalid character.

Experts, Kindly guide us whether we are doing the correct coding to accomplish our desired task.

Thanks,
eprm.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
$StringValue = "abcdefghijklmnopqrstuvwxyz0123456789_-.@ABCDEFGHIJKLMNOPQRSTUVWXYZÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ()'&/ ";
$value = $_POST["txtName"];
for($i=0; $i < strlen(utf8_decode($value)); $i++)
{
 $char_pos=0;
 $char_sub=mb_substr($value, $i, 1,'UTF-8');
 $char_pos=mb_strpos($StringValue, $char_sub, 0,'UTF-8');
 if(($char_pos) >= 0)
 {
  echo 'VALID Char';
 }
 else
 {
  echo 'Invalid Characters found';
 }
}
[+][-]11/07/09 07:46 AM, ID: 25766659Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/07/09 11:05 PM, ID: 25769673Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]11/08/09 06:00 AM, ID: 25770475Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]11/08/09 06:15 AM, ID: 25770536Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 - Hierarchy / EE_QW_3_20080625