Haritz
Haritz

Reputation: 1752

substr function in PHP5

I am developing an application were I need to use the next PHP5 code:

<?php

$Hurrengo_Hitza = 'word_3';

$Handiena_MarkID = 0;  
$Handiena_Hitzarentzat = -2;
$Hitza_Index = substr($Hurrengo_Hitza , 5);

    print $Handiena_MarkID . $Hitza_index . $Handiena_Hitzarentzat;

The result I am looking for is 0 3 -2 and the result I am getting is 0-2. Which is the problem?

Upvotes: 0

Views: 228

Answers (4)

Hampus Nilsson
Hampus Nilsson

Reputation: 6822

You have a lowercase i in $Hitza_index when printing, while it's uppercase when assigning.

Upvotes: 0

Fad
Fad

Reputation: 9858

This is just a minor case of typo and case sensitivity.

print $Handiena_MarkID . $Hitza_index . $Handiena_Hitzarentzat;

Notice in that line it says $Hitza_index and not $Hitza_Index. Since variables in PHP are case-sensitive, you need to change that to $Hitza_Index.

Upvotes: 1

mrjimoy_05
mrjimoy_05

Reputation: 3568

Try this:

$Hitza_Index = substr($Hurrengo_Hitza, -1);

Upvotes: 0

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272487

Variables in PHP are case-sensitive.

Upvotes: 0

Related Questions