1.First download the plugin exec-php.
[tweegi-button name="Download php-exec plugin"]
2.Upload it in your plugin directory and activate.
3. Go to Settings->Exec-php and give a tick on the ‘execute php in text widget” if you want to write php script in widget texy area.
4. Go to User->My profile and put a tick on “Disable the visual editor when writing” .
And put a tick on “disable WYSIWYG conversion warning”.
Now go to new post and try to test something
<?php echo “Hello” ?>
So now by these above method you can write php script in WordPress posts easily.