[php] varchar opdelen

Pagina: 1
Acties:

  • MP83
  • Registratie: Januari 2000
  • Laatst online: 31-01 18:11
Ik wil graag checken of de 5e letter/cijfer van de varchar die ik opvraag een 2 is.

De waarde opvragen met $waarde[4] zoals bij een array werkt helaas niet bij mij :?

Weet iemand hoe het wel kan?

Mocht er meer info nodig zijn dan hoor ik het wel :)

Alvast bedankt! :)

  • djc
  • Registratie: December 2001
  • Laatst online: 08-09-2025

djc

substr($str, 4, 1);

Rustacean


  • marcusk
  • Registratie: Februari 2001
  • Laatst online: 26-09-2023
of met een typecast:
code:
1
2
$waarde = (string)$waarde;
print($waarde{4});

(Characters within strings may be accessed by specifying the zero-based offset of the desired character after the string in curly braces.

Note: For backwards compatibility, you can still use the array-braces. However, this syntax is deprecated as of PHP 4.)

  • Grum
  • Registratie: Juni 2001
  • Niet online
En strings zijn character arrays dus $bla[3] is het 4'e char in $bla (wat btw ook een undocumented feature is van php)

  • MP83
  • Registratie: Januari 2000
  • Laatst online: 31-01 18:11
Ok! Thx :)