If it’s only for phonebook matching, CID Superfecta has the ability to modify the incoming CID just for the lookup. You won’t need any custom code. See
https://community.freepbx.org/t/phone-book-look-up/71996
This has the advantages of leaving the displayed number unchanged (easier for the end user to recognize) and not breaking follow me / forwarding, but has the disadvantage of not allowing the user to return a call from his device’s history.
IMO, it would be much cleaner to have a system that does not use an initial 0 for external calls, but if you switch over, you’ll have some misdials for a while because users will have the habit of dialing the 0. In many countries you could make the 0 optional, but numbers in Germany have variable length, so it won’t work here. For example, 0039062223333 could be a number in Bebertal with an initial 0, or a number in Rome without the 0.
However, if most of your calls are local, you likely could allow an optional 0 for those. For example in Berlin, 030 123 456 78 could alternatively be dialed 0 030 123 456 78 without confusion, because a number in Greece would have 10 digits after the country code.