Get scripthash for known scriptPubKey in PHP I have to query addresses in ElectrumX server. How do I generate scripthash for a known scriptPubKey in PHP?

Example address:

array (
  'isvalid' =&gt; true,
  'address' =&gt; '1MUz4VMYui5qY1mxUiG8BQ1Luv6tqkvaiL',
  'scriptPubKey' =&gt; '76a914e0ad60c897901128662623c500a4a6079e99cd3e88ac',
  'isscript' =&gt; false,
  'iswitness' =&gt; false,
)


I tried:

hash('sha256', hex2bin('76a914e0ad60c897901128662623c500a4a6079e99cd3e88ac'))


But it seems to be wrong.
I found the solution replicating https://github.com/janoside/btc-rpc-explorer/blob/master/app/api/electrumAddressApi.js

$scriptPubKey = '76a914e0ad60c897901128662623c500a4a6079e99cd3e88ac';

$addrScripthash = hash('sha256', hex2bin($scriptPubKey));
$re = '/.{2}/';
preg_match_all($re, $addrScripthash, $matches, PREG_PATTERN_ORDER, 0);
$addrScripthash = implode('', array_reverse($matches[0]));

print($addrScripthash);