0

i just want to check whether my $_POST has 'Project :' in it or not. But its getting failed ! Can i know why ?

if (substr($_POST['project'],0,8) == 'Project :'){ $project = $_POST['project']; }

Vamsi Krishna
  • 162
  • 1
  • 13

3 Answers3

4

I suggest reading the documentation on the substr function. The second parameter is the starting position, the third is the length. That means you can only have an 8 character output.

Project :
        ^
123456789

You got one character too many. Try changing the 0,8 to 0,9

Bing
  • 3,071
  • 6
  • 42
  • 81
0

You can try the following

if(strpos($_POST['project'], 'Project :') !== false) {

   $project = $_POST['project'];
}
Anandhu Nadesh
  • 672
  • 2
  • 11
  • 20
0

Using the link I provided you in a comment.

If the use of substr isn't mandatory, I suggest you to use strpos that way:

if (strpos($_POST['project'], 'Project :') !== false) {
    $project = $_POST['project'];;
}

Hope it helps.

Takit Isy
  • 9,688
  • 3
  • 23
  • 47