How to generate addresses in PHP I need some PHP code to generate bitcoin addresses from a given public key.

I can only find algorithms to generate addresses from the master private key but according to https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses
the private key is not required at all.
Use BitWasp Bitcoin-php library
https://github.com/Bit-Wasp/bitcoin-php

&lt;?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;

$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey-&gt;getPublicKey();
$address = $publicKey-&gt;getAddress(); // returns AddressInterface
echo $address-&gt;getAddress($network); // prints address for $network as string


If you want to create Bitcoin address from Public key string check documentation for Factory classes

or newer versions:

&lt;?php
use BitWasp\Bitcoin\Bitcoin;
use BitWasp\Bitcoin\Address\AddressCreator;
use BitWasp\Bitcoin\Key\PrivateKeyFactory;
use BitWasp\Bitcoin\Key\KeyToScript\Factory\P2pkhScriptDataFactory; 

$network = Bitcoin::getNetwork();
$privateKey = PrivateKeyFactory::create(true);
$publicKey = $privateKey-&gt;getPublicKey();

$addrCreator = new AddressCreator();
$factory = new P2pkhScriptDataFactory();
$scriptPubKey = $factory-&gt;convertKey($publicKey)-&gt;getScriptPubKey();
$address = $addrCreator-&gt;fromOutputScript($scriptPubKey); // returns AddressInterface
echo $address-&gt;getAddress($network); // prints address for $network as string