You can add php-code to your custom block with php tags, and operate with contents using $block_body variable. This variable consists of all the html text you have in your block.
To activate PHP code functionality for custom blocks, please go to Administration > System > Global Settings and select where you want to insert your php code. Also, don't forget to switch from the 'WYSIWYG HTML Editor' to 'Textarea Editor' to view the code in your custom blocks correctly. Then open your custom block and insert your php code in the 'Block Content' textarea.
The basic code will look like this:
Feel free to add any text here <br> Something <?php echo "1";>
// simple php code
or like this:
Feel free to add any text here <br> Something <?php $block_body = str_replace("Something", "Anything", $block_body); ?>
// php code with a variable replacement
Here is an example of code that can be used in the footer body: