PHP Reference

Quick Reference

The PHP base_convert() function converts a number from one number base to another.

<?php
$hex = 'E198';
echo base_convert($hex, 16, 8);
?>

Syntax

base_convert(number, frombase, tobase)

Parameters

ParameterDescription
numberSpecifies the number to convert (required)
frombaseSpecifies the original base of number between 2 and 36, inclusive; digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35 (required)
tobaseSpecifies the base to convert to between 2 and 36, inclusive; digits in numbers with a base higher than 10 will be represented with the letters a-z, with a meaning 10, b meaning 11 and z meaning 35 (required)

PHP Notes:

  • When using PHP, single or double quotation marks are acceptable and work identically to one another; choose whichever you prefer, and stay consistent
  • Arrays count starting from zero NOT one; so item 1 is position [0], item 2 is position [1], and item 3 is position [2] … and so on

We’d like to acknowledge that we learned a great deal of our coding from W3Schools and TutorialsPoint, borrowing heavily from their teaching process and excellent code examples. We highly recommend both sites to deepen your experience, and further your coding journey. We’re just hitting the basics here at 1SMARTchicken.