php equivalent of bytes (str,’latin-1′) in python

the context is :

signed_str = hmac.new(bytes(secret_key, 'latin-1'),
                  msg=bytes(prepared_str, 'latin-1'),
                  digestmod=hashlib.sha256).hexdigest().lower()

I manage to get this segment of code work nicely but the php I tried is not even close

<php

$signed_str = strtolower( base64_encode (hash_hmac('sha256',$prepared_str , $secretKey) ) )  ;

Generally, i understand the whole thing but not the exact details to convert it to php.
And when we are at it, it would be perfect if hexdigest has a php equivalent.